Create, show, and delete indexes
This page describes how to create, list, and delete search-performance indexes. The following index types are included in this category:
For information about how search-performance indexes are used in Cypher® queries, see Using search-performance indexes.
CREATE INDEX
Creating an index is done with the CREATE … INDEX …
command.
If no index type is specified in the create command a range index will be created.
Best practice is to give the index a name when it is created. If the index is not explicitly named, it gets an auto-generated name.
The index name must be unique among both indexes and constraints. |
The CREATE INDEX
command is optionally idempotent.
This mean that its default behavior is to throw an error if an attempt is made to create the same index twice.
If IF NOT EXISTS
is appended to the command, no error is thrown and nothing happens should an index with the same name or same schema and index type already exist.
It may still throw an error if conflicting constraints exist, such as constraints with the same name or schema and backing index type.
As of Neo4j 5.17, an informational notification is instead returned showing the existing index which blocks the creation.
Index configuration settings can be specified using the OPTIONS
clause.
However, not all indexes have available configuration settings.
In those cases, nothing needs to be specified and the OPTIONS
map should be omitted from the query.
Creating an index requires the CREATE INDEX privilege.
|
An index cannot be used while its state is POPULATING , which occurs immediately after it is created.
To check the state of an index — whether it is ONLINE (usable) or POPULATING (still being built; the populationPercent column shows the progress of the index creation) — run the following command: SHOW INDEXES .
|
Create a range index
Creating a range index can be done with the CREATE INDEX
command.
Note that the index name must be unique.
Range indexes have no supported index configuration.
Supported predicates
Range indexes support most types of predicates:
Predicate | Syntax |
---|---|
Equality check. |
|
List membership check. |
|
Existence check. |
|
Range search. |
|
Prefix search. |
|
Examples
Create a single-property range index for nodes
The following statement will create a named range index on all nodes labeled with Person
and which have the surname
property.
CREATE INDEX node_range_index_name FOR (n:Person) ON (n.surname)
Create a single-property range index for relationships
The following statement will create a named range index on all relationships with relationship type KNOWS
and property since
.
CREATE INDEX rel_range_index_name FOR ()-[r:KNOWS]-() ON (r.since)
Create a composite range index for nodes
A range index on multiple properties is also called a composite index. For node range indexes, only nodes with the specified label and that contain all the specified properties will be added to the index.
The following statement will create a named composite range index on all nodes labeled with Person
and which have both an age
and country
property.
CREATE INDEX composite_range_node_index_name FOR (n:Person) ON (n.age, n.country)
Create a composite range index for relationships
A range index on multiple properties is also called a composite index. For relationship range indexes, only relationships with the specified type and that contain all the specified properties will be added to the index.
The following statement will create a named composite range index on all relationships labeled with PURCHASED
and which have both a date
and amount
property.
CREATE INDEX composite_range_rel_index_name FOR ()-[r:PURCHASED]-() ON (r.date, r.amount)
Create a range index using a parameter
This feature was introduced in Neo4j 5.16.
The following statement will create a named range index on all nodes with a Person
label and a firstname
property using a parameter for the index name.
{
"name": "range_index_param"
}
CREATE INDEX $name FOR (n:Person) ON (n.firstname)
Create a range index only if it does not already exist
If it is not known whether an index exists or not, add IF NOT EXISTS
to ensure it does.
IF NOT EXISTS
CREATE INDEX node_range_index_name IF NOT EXISTS
FOR (n:Person) ON (n.surname)
The index will not be created if there already exists an index with the same schema and type, same name or both. As of Neo4j 5.17, an informational notification is instead returned.
`CREATE RANGE INDEX node_range_index_name IF NOT EXISTS FOR (e:Person) ON (e.surname)` has no effect.
`RANGE INDEX node_range_index_name FOR (e:Person) ON (e.surname)` already exists.
Create a text index
Creating a text index can be done with the CREATE TEXT INDEX
command.
Note that the index name must be unique.
Text indexes have no supported index configuration and, as of Neo4j 5.1, they have two index providers available, text-2.0
(default) and text-1.0
(deprecated).
Supported predicates
Text indexes only solve predicates operating on STRING
values.
The following predicates that only operate on STRING
values are always solvable by a text index:
-
STARTS WITH
-
ENDS WITH
-
CONTAINS
However, other predicates are only used when it is known that the property is compared to a STRING
:
-
n.prop = "string"
-
n.prop IN ["a", "b", "c"]
This means that a text index is not able to solve, for example, e.g. a.prop = b.prop
, unless a property type constraint also exists on the property.
Text indexes support the following predicates:
Predicate | Syntax |
---|---|
Equality check. |
|
List membership check. |
|
Prefix search. |
|
Suffix search. |
|
Substring search. |
|
As of Neo4j 5.11, the above set of predicates can be extended with the use of property type constraints. See the section about index compatibility and property type constraints for more information.
Text indexes are only used for exact query matches. To perform approximate matches (including, for example, variations and typos), and to compute a similarity score between STRING values, use semantic full-text indexes instead.
|
Examples
Create a node text index
The following statement will create a named text index on all nodes labeled with Person
and which have the nickname
STRING
property.
CREATE TEXT INDEX node_text_index_nickname FOR (n:Person) ON (n.nickname)
Create a relationship text index
The following statement will create a named text index on all relationships with relationship type KNOWS
and STRING
property interest
.
CREATE TEXT INDEX rel_text_index_name FOR ()-[r:KNOWS]-() ON (r.interest)
Create a text index using a parameter
This feature was introduced in Neo4j 5.16.
The following statement will create a named text index on all nodes with the Person
label the favoriteColor
STRING
property using a parameter for the index name.
{
"name": "text_index_param"
}
CREATE TEXT INDEX $name FOR (n:Person) ON (n.favoriteColor)
Create a text index only if it does not already exist
If it is not known whether an index exists or not, add IF NOT EXISTS
to ensure it does.
The following statement will attempt to create a named text index on all nodes labeled with Person
and which have the nickname
STRING
property.
IF NOT EXISTS
CREATE TEXT INDEX node_index_name IF NOT EXISTS FOR (n:Person) ON (n.nickname)
Note that the index will not be created if there already exists an index with the same schema and type, same name or both. As of Neo4j 5.17, an informational notification is instead returned.
`CREATE TEXT INDEX node_index_name IF NOT EXISTS FOR (e:Person) ON (e.nickname)` has no effect.
`TEXT INDEX node_text_index_nickname FOR (e:Person) ON (e.nickname)` already exists.
Create a point index
Creating a point index can be done with the CREATE POINT INDEX
command.
Note that the index name must be unique.
Point indexes have supported index configuration.
Supported predicates
Point indexes only solve predicates operating on POINT
values.
Point indexes support the following predicates:
Predicate | Syntax |
---|---|
Property point value. |
|
Within bounding box. |
|
Distance. |
|
As of Neo4j 5.11, the above set of predicates can be extended with the use of property type constraints. See Index compatibility and property type constraints for more information.
To learn more about the spatial data types supported by Cypher, see the page about Spatial values. |
Examples
Create a node point index
The following statement will create a named point index on all nodes labeled with Person
and which have the sublocation
POINT
property.
CREATE POINT INDEX node_point_index_name FOR (n:Person) ON (n.sublocation)
Create a relationship point index
The following statement will create a named point index on all relationships with relationship type STREET
and POINT
property intersection
.
CREATE POINT INDEX rel_point_index_name FOR ()-[r:STREET]-() ON (r.intersection)
Create a point index using a parameter
This feature was introduced in Neo4j 5.16.
The following statement will create a named point index on all relationships with relationship type STREET
and POINT
property coordinate
using a parameter for the index name.
{
"name": "point_index_param"
}
CREATE POINT INDEX $name FOR ()-[r:STREET]-() ON (r.coordinate)
Create a point index only if it does not already exist
If it is not known whether an index exists or not, add IF NOT EXISTS
to ensure it does.
IF NOT EXISTS
CREATE POINT INDEX node_point_index IF NOT EXISTS
FOR (n:Person) ON (n.sublocation)
Note that the index will not be created if there already exists an index with the same schema and type, same name or both. As of Neo4j 5.17, an informational notification is instead returned.
`CREATE POINT INDEX node_point_index IF NOT EXISTS FOR (e:Person) ON (e.sublocation)` has no effect.
`POINT INDEX node_point_index_name FOR (e:Person) ON (e.sublocation)` already exists.
Create a point index specifying the index configuration
To create a point index with a specific index configuration, the indexConfig
settings in the OPTIONS
clause.
The valid configuration settings are:
-
spatial.cartesian.min
(default value: [-1000000.0
,-1000000.0
]) -
spatial.cartesian.max
(default value: [1000000.0
,1000000.0
]) -
spatial.cartesian-3d.min
(default value: [-1000000.0
,-1000000.0
,-1000000.0
]) -
spatial.cartesian-3d.max
(default value: [1000000.0
,1000000.0
,1000000.0`
]) -
spatial.wgs-84.min
(default value: [-180.0
,-90.0
]) -
spatial.wgs-84.max
(default value: [-180.0
,-90.0
]) -
spatial.wgs-84-3d.min
(default value: [-180.0
,-90.0
,-1000000.0
]) -
spatial.wgs-84-3d.max
(default value: [180.0
,90.0
,1000000.0
])
The following statement will create a point index specifying the spatial.cartesian.min
and spatial.cartesian.max
settings.
CREATE POINT INDEX point_index_with_config
FOR (n:Label) ON (n.prop2)
OPTIONS {
indexConfig: {
`spatial.cartesian.min`: [-100.0, -100.0],
`spatial.cartesian.max`: [100.0, 100.0]
}
}
Note that the wgs-84 and 3D cartesian settings, which are not specified in this example, will be set with their respective default values.
Create a token lookup index
Two token lookup indexes are created by default when creating a Neo4j database (one node label lookup index and one relationship type lookup index). Only one node label and one relationship type lookup index can exist at the same time.
If a token lookup index has been deleted, it can be recreated with the CREATE LOOKUP INDEX
command.
Note that the index name must be unique.
Token lookup indexes have no supported index configuration.
Supported predicates
Token lookup indexes are present by default and solve only node label and relationship type predicates:
Predicate | Syntax (example) |
---|---|
Node label predicate. |
|
Relationship type predicate. |
|
Token lookup indexes improve the performance of Cypher queries and the population of other indexes. Dropping these indexes may lead to severe performance degradation. |
Examples
Create a node label lookup index
The following statement will create a named node label lookup index on all nodes with one or more labels:
CREATE LOOKUP INDEX node_label_lookup_index FOR (n) ON EACH labels(n)
Only one node label lookup index can exist at a time. |
Create a relationship type lookup index
The following statement will create a named relationship type lookup index on all relationships with any relationship type.
CREATE LOOKUP INDEX rel_type_lookup_index FOR ()-[r]-() ON EACH type(r)
Only one relationship type lookup index can exist at a time. |
Create a token lookup index only if it does not already exist
If it is not known whether an index exists or not, add IF NOT EXISTS
to ensure it does.
IF NOT EXISTS
CREATE LOOKUP INDEX node_label_lookup IF NOT EXISTS FOR (n) ON EACH labels(n)
The index will not be created if there already exists an index with the same schema and type, same name or both. As of Neo4j 5.17, an informational notification is instead returned.
`CREATE LOOKUP INDEX node_label_lookup IF NOT EXISTS FOR (e) ON EACH labels(e)` has no effect.
`LOOKUP INDEX node_label_lookup_index FOR (e) ON EACH labels(e)` already exists.
Creating an index when a conflicting index or constraint exists
Failure to create an already existing index
Create an index on the property title
on nodes with the Book
label, when that index already exists.
CREATE INDEX bookTitleIndex FOR (book:Book) ON (book.title)
In this case, the index can not be created because it already exists.
There already exists an index (:Book {title}).
Using IF NOT EXISTS
when creating the index would result in no error and would not create a new index.
Failure to create an index with the same name as an already existing index
Create a named index on the property numberOfPages
on nodes with the Book
label, when an index with the given name already exists.
The index type of the existing index does not matter.
CREATE INDEX indexOnBooks FOR (book:Book) ON (book.numberOfPages)
In this case, the index cannot be created because there already exists an index with the given name.
There already exists an index called 'indexOnBooks'.
Using IF NOT EXISTS
when creating the index would result in no error and would not create a new index.
Failure to create an index when a constraint already exists
Create an index on the property isbn
on nodes with the Book
label, when an index-backed constraint already exists on that schema.
This is only relevant for range indexes.
CREATE INDEX bookIsbnIndex FOR (book:Book) ON (book.isbn)
In this case, the index can not be created because an index-backed constraint already exists on that label and property combination.
There is a uniqueness constraint on (:Book {isbn}), so an index is already created that matches this.
Failure to create an index with the same name as an already existing constraint
Create a named index on the property numberOfPages
on nodes with the Book
label, when a constraint with the given name already exists.
CREATE INDEX bookRecommendations FOR (book:Book) ON (book.recommendations)
In this case, the index can not be created because there already exists a constraint with the given name.
There already exists a constraint called 'bookRecommendations'.
SHOW INDEXES
Listing indexes can be done with SHOW INDEXES
.
Listing indexes requires the SHOW INDEX privilege.
|
Examples
Listing all indexes
To list all indexes with the default output columns, the SHOW INDEXES
command can be used.
If all columns are required, use SHOW INDEXES YIELD *
.
SHOW INDEXES
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | id | name | state | populationPercent | type | entityType | labelsOrTypes | properties | indexProvider | owningConstraint | lastRead | readCount | +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | 3 | "composite_range_node_index_name" | "ONLINE" | 100.0 | "RANGE" | "NODE" | ["Person"] | ["age", "country"] | "range-1.0" | NULL | NULL | 0 | | 4 | "composite_range_rel_index_name" | "ONLINE" | 100.0 | "RANGE" | "RELATIONSHIP" | ["PURCHASED"] | ["date", "amount"] | "range-1.0" | NULL | 2023-03-13T11:41:44.537Z | 1 | | 16 | "example_index" | "ONLINE" | 100.0 | "RANGE" | "NODE" | ["Book"] | ["title"] | "range-1.0" | NULL | 2023-04-10T15:41:44.537Z | 2 | | 17 | "indexOnBooks" | "ONLINE" | 100.0 | "TEXT" | "NODE" | ["Label1"] | ["prop1"] | "text-2.0" | NULL | NULL | 0 | | 14 | "node_label_lookup_index" | "ONLINE" | 100.0 | "LOOKUP" | "NODE" | NULL | NULL | "token-lookup-1.0" | NULL | 2023-04-13T08:11:15.537Z | 10 | | 10 | "node_point_index_name" | "ONLINE" | 100.0 | "POINT" | "NODE" | ["Person"] | ["sublocation"] | "point-1.0" | NULL | 2023-04-05T16:21:44.692Z | 1 | | 1 | "node_range_index_name" | "ONLINE" | 100.0 | "RANGE" | "NODE" | ["Person"] | ["surname"] | "range-1.0" | NULL | 2022-12-30T02:01:44.537Z | 6 | | 6 | "node_text_index_nickname" | "ONLINE" | 100.0 | "TEXT" | "NODE" | ["Person"] | ["nickname"] | "text-2.0" | NULL | 2023-04-13T11:41:44.537Z | 2 | | 12 | "point_index_param" | "ONLINE" | 100.0 | "POINT" | "RELATIONSHIP" | ["STREET"] | ["coordinate"] | "point-1.0" | NULL | NULL | 0 | | 13 | "point_index_with_config" | "ONLINE" | 100.0 | "POINT" | "NODE" | ["Label"] | ["prop2"] | "point-1.0" | NULL | NULL | 0 | | 5 | "range_index_param" | "ONLINE" | 100.0 | "RANGE" | "NODE" | ["Person"] | ["firstname"] | "range-1.0" | NULL | 2023-12-13T08:23:53.338Z | 2 | | 11 | "rel_point_index_name" | "ONLINE" | 100.0 | "POINT" | "RELATIONSHIP" | ["STREET"] | ["intersection"] | "point-1.0" | NULL | 2023-03-03T13:37:42.537Z | 2 | | 2 | "rel_range_index_name" | "ONLINE" | 100.0 | "RANGE" | "RELATIONSHIP" | ["KNOWS"] | ["since"] | "range-1.0" | NULL | 2023-04-12T10:41:44.692Z | 5 | | 7 | "rel_text_index_name" | "ONLINE" | 100.0 | "TEXT" | "RELATIONSHIP" | ["KNOWS"] | ["interest"] | "text-2.0" | NULL | 2023-04-01T10:40:44.537Z | 3 | | 15 | "rel_type_lookup_index" | "ONLINE" | 100.0 | "LOOKUP" | "RELATIONSHIP" | NULL | NULL | "token-lookup-1.0" | NULL | 2023-04-12T21:41:44.537Z | 7 | | 8 | "text_index_param" | "ONLINE" | 100.0 | "TEXT" | "NODE" | ["Person"] | ["favoriteColor"] | "text-2.0" | NULL | NULL | 0 | | 18 | "uniqueBookIsbn" | "ONLINE" | 100.0 | "RANGE" | "NODE" | ["Book"] | ["isbn"] | "range-1.0" | "uniqueBookIsbn" | 2023-04-13T11:41:44.692Z | 6 | +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 18 rows
One of the output columns from SHOW INDEXES
is the name of the index.
This can be used to drop the index with the DROP INDEX
command.
Listing specific columns
It is possible to return only specific columns of the available indexes using the YIELD
clause:
SHOW INDEXES
YIELD name, type, indexProvider AS provider, options, createStatement
RETURN name, type, provider, options.indexConfig AS config, createStatement
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | name | type | provider | config | createStatement | +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | "composite_range_node_index_name" | "RANGE" | "range-1.0" | {} | "CREATE RANGE INDEX `composite_range_node_index_name` FOR (n:`Person`) ON (n.`age`, n.`country`)" | | "composite_range_rel_index_name" | "RANGE" | "range-1.0" | {} | "CREATE RANGE INDEX `composite_range_rel_index_name` FOR ()-[r:`PURCHASED`]-() ON (r.`date`, r.`amount`)" | | "example_index" | "RANGE" | "range-1.0" | {} | "CREATE RANGE INDEX `example_index` FOR (n:`Book`) ON (n.`title`)" | | "indexOnBooks" | "TEXT" | "text-2.0" | {} | "CREATE TEXT INDEX `indexOnBooks` FOR (n:`Label1`) ON (n.`prop1`)" | | "index_343aff4e" | "LOOKUP" | "token-lookup-1.0" | {} | "CREATE LOOKUP INDEX `index_343aff4e` FOR (n) ON EACH labels(n)" | | "index_f7700477" | "LOOKUP" | "token-lookup-1.0" | {} | "CREATE LOOKUP INDEX `index_f7700477` FOR ()-[r]-() ON EACH type(r)" | | "node_point_index_name" | "POINT" | "point-1.0" | {`spatial.cartesian.min`: [-1000000.0, -1000000.0], `spatial.wgs-84.min`: [-180.0, -90.0], `spatial.wgs-84.max`: [180.0, 90.0], `spatial.cartesian.max`: [1000000.0, 1000000.0], `spatial.wgs-84-3d.max`: [180.0, 90.0, 1000000.0], `spatial.cartesian-3d.min`: [-1000000.0, -1000000.0, -1000000.0], `spatial.cartesian-3d.max`: [1000000.0, 1000000.0, 1000000.0], `spatial.wgs-84-3d.min`: [-180.0, -90.0, -1000000.0]} | "CREATE POINT INDEX `node_point_index_name` FOR (n:`Person`) ON (n.`sublocation`) OPTIONS {indexConfig: {`spatial.cartesian-3d.max`: [1000000.0, 1000000.0, 1000000.0],`spatial.cartesian-3d.min`: [-1000000.0, -1000000.0, -1000000.0],`spatial.cartesian.max`: [1000000.0, 1000000.0],`spatial.cartesian.min`: [-1000000.0, -1000000.0],`spatial.wgs-84-3d.max`: [180.0, 90.0, 1000000.0],`spatial.wgs-84-3d.min`: [-180.0, -90.0, -1000000.0],`spatial.wgs-84.max`: [180.0, 90.0],`spatial.wgs-84.min`: [-180.0, -90.0]}}" | | "node_range_index" | "RANGE" | "range-1.0" | {} | "CREATE RANGE INDEX `node_range_index` FOR (n:`Person`) ON (n.`surname`)" | | "node_text_index_nickname" | "TEXT" | "text-2.0" | {} | "CREATE TEXT INDEX `node_text_index_nickname` FOR (n:`Person`) ON (n.`nickname`)" | | "point_index_with_config" | "POINT" | "point-1.0" | {`spatial.cartesian.min`: [-100.0, -100.0], `spatial.wgs-84.min`: [-180.0, -90.0], `spatial.wgs-84.max`: [180.0, 90.0], `spatial.cartesian.max`: [100.0, 100.0], `spatial.wgs-84-3d.max`: [180.0, 90.0, 1000000.0], `spatial.cartesian-3d.min`: [-1000000.0, -1000000.0, -1000000.0], `spatial.cartesian-3d.max`: [1000000.0, 1000000.0, 1000000.0], `spatial.wgs-84-3d.min`: [-180.0, -90.0, -1000000.0]} | "CREATE POINT INDEX `point_index_with_config` FOR (n:`Label`) ON (n.`prop2`) OPTIONS {indexConfig: {`spatial.cartesian-3d.max`: [1000000.0, 1000000.0, 1000000.0],`spatial.cartesian-3d.min`: [-1000000.0, -1000000.0, -1000000.0],`spatial.cartesian.max`: [100.0, 100.0],`spatial.cartesian.min`: [-100.0, -100.0],`spatial.wgs-84-3d.max`: [180.0, 90.0, 1000000.0],`spatial.wgs-84-3d.min`: [-180.0, -90.0, -1000000.0],`spatial.wgs-84.max`: [180.0, 90.0],`spatial.wgs-84.min`: [-180.0, -90.0]}}" | | "rel_point_index_name" | "POINT" | "point-1.0" | {`spatial.cartesian.min`: [-1000000.0, -1000000.0], `spatial.wgs-84.min`: [-180.0, -90.0], `spatial.wgs-84.max`: [180.0, 90.0], `spatial.cartesian.max`: [1000000.0, 1000000.0], `spatial.wgs-84-3d.max`: [180.0, 90.0, 1000000.0], `spatial.cartesian-3d.min`: [-1000000.0, -1000000.0, -1000000.0], `spatial.cartesian-3d.max`: [1000000.0, 1000000.0, 1000000.0], `spatial.wgs-84-3d.min`: [-180.0, -90.0, -1000000.0]} | "CREATE POINT INDEX `rel_point_index_name` FOR ()-[r:`STREET`]-() ON (r.`intersection`) OPTIONS {indexConfig: {`spatial.cartesian-3d.max`: [1000000.0, 1000000.0, 1000000.0],`spatial.cartesian-3d.min`: [-1000000.0, -1000000.0, -1000000.0],`spatial.cartesian.max`: [1000000.0, 1000000.0],`spatial.cartesian.min`: [-1000000.0, -1000000.0],`spatial.wgs-84-3d.max`: [180.0, 90.0, 1000000.0],`spatial.wgs-84-3d.min`: [-180.0, -90.0, -1000000.0],`spatial.wgs-84.max`: [180.0, 90.0],`spatial.wgs-84.min`: [-180.0, -90.0]}}" | | "rel_range_index_name" | "RANGE" | "range-1.0" | {} | "CREATE RANGE INDEX `rel_range_index_name` FOR ()-[r:`KNOWS`]-() ON (r.`since`)" | | "rel_text_index_name" | "TEXT" | "text-2.0" | {} | "CREATE TEXT INDEX `rel_text_index_name` FOR ()-[r:`KNOWS`]-() ON (r.`interest`)" | | "uniqueBookIsbn" | "RANGE" | "range-1.0" | {} | "CREATE CONSTRAINT `uniqueBookIsbn` FOR (n:`Book`) REQUIRE (n.`isbn`) IS UNIQUE" | +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Note that YIELD
is mandatory if the RETURN
clause is used.
RETURN
is not, however, mandatory when the YIELD clause is used.
Listing indexes with filtering
The SHOW INDEX
command can be filtered in various ways.
For example, to show only range indexes, use SHOW RANGE INDEXES
.
Another more flexible way of filtering the output is to use the WHERE
clause.
An example is to only show indexes not belonging to constraints.
To show only range indexes that does not belong to a constraint we can combine the filtering versions.
SHOW RANGE INDEXES WHERE owningConstraint IS NULL
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | id | name | state | populationPercent | type | entityType | labelsOrTypes | properties | indexProvider | owningConstraint | lastRead | readCount | +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | 3 | "composite_range_node_index_name" | "ONLINE" | 100.0 | "RANGE" | "NODE" | ["Person"] | ["age", "country"] | "range-1.0" | NULL | NULL | 0 | | 4 | "composite_range_rel_index_name" | "ONLINE" | 100.0 | "RANGE" | "RELATIONSHIP" | ["PURCHASED"] | ["date", "amount"] | "range-1.0" | NULL | 2023-03-13T11:41:44.537Z | 1 | | 16 | "example_index" | "ONLINE" | 100.0 | "RANGE" | "NODE" | ["Book"] | ["title"] | "range-1.0" | NULL | 2023-04-10T15:41:44.537Z | 2 | | 1 | "node_range_index_name" | "ONLINE" | 100.0 | "RANGE" | "NODE" | ["Person"] | ["surname"] | "range-1.0" | NULL | 2022-12-30T02:01:44.537Z | 6 | | 5 | "range_index_param" | "ONLINE" | 100.0 | "RANGE" | "NODE" | ["Person"] | ["firstname"] | "range-1.0" | NULL | 2023-12-13T08:23:53.338Z | 2 | | 2 | "rel_range_index_name" | "ONLINE" | 100.0 | "RANGE" | "RELATIONSHIP" | ["KNOWS"] | ["since"] | "range-1.0" | NULL | 2023-04-12T10:41:44.692Z | 5 | +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 6 rows
This will only return the default output columns.
To get all columns, use:
SHOW RANGE INDEXES YIELD * WHERE owningConstraint IS NULL
Result columns for listing indexes
The below table contains the full information about all columns returned by the SHOW INDEXES YIELD *
command:
Column | Description | Type |
---|---|---|
|
The id of the index. Default Output |
|
|
Name of the index (explicitly set by the user or automatically assigned). Default Output |
|
|
Current state of the index. Default Output |
|
|
% of index population. Default Output |
|
|
The IndexType of this index ( |
|
|
Type of entities this index represents (nodes or relationship). Default Output |
|
|
The labels or relationship types of this index. Default Output |
|
|
The properties of this index. Default Output |
|
|
The index provider for this index. Default Output |
|
|
The name of the constraint the index is associated with or |
|
|
The last time the index was used for reading.
Returns |
|
|
The number of read queries that have been issued to this index since |
|
|
The time when usage statistics tracking started for this index, or |
|
|
Information retrieved from the |
|
|
The failure description of a failed index. |
|
|
Statement used to create the index. |
|
DROP INDEX
An index can be dropped (removed) using the name with the DROP INDEX index_name
command.
This command can drop indexes of any type, except those backing constraints.
The name of the index can be found using the SHOW INDEXES
command, given in the output column name
.
DROP INDEX index_name [IF EXISTS]
The DROP INDEX
command is optionally idempotent.
This means that its default behavior is to throw an error if an attempt is made to drop the same index twice.
With IF EXISTS
, no error is thrown and nothing happens should the index not exist.
As of Neo4j 5.17, an informational notification is instead returned detailing that the index does not exist.
Dropping an index requires the DROP INDEX privilege.
|
Examples
Drop an index
The following statement will attempt to drop the index named example_index
.
DROP INDEX example_index
If an index with that name exists it is removed, if not the command fails.
Drop an index using a parameter
This feature was introduced in Neo4j 5.16.
The following statement will attempt to drop the index named range_index_param
using a parameter for the index name.
{
"name": "range_index_param"
}
DROP INDEX $name
If an index with that name exists it is removed, if not the command fails.
Failure to drop an index backing a constraint
It is not possible to drop indexes that back constraints.
DROP INDEX uniqueBookIsbn
Unable to drop index: Index belongs to constraint: `uniqueBookIsbn`
Dropping the index-backed constraint will also remove the backing index. For more information, see Drop a constraint by name.
Drop a non-existing index
If it is uncertain if an index exists and you want to drop it if it does but not get an error should it not, use IF EXISTS
.
The following statement will attempt to drop the index named missing_index_name
.
IF EXISTS
DROP INDEX missing_index_name IF EXISTS
If an index with that name exists it is removed, if not the command does nothing. As of Neo4j 5.17, additionally, an informational notification is returned.
`DROP INDEX missing_index_name IF EXISTS` has no effect. `missing_index_name` does not exist.