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]
Specifying the index configuration can be combined with specifying index provider.
Though only one valid value exists for the index provider, point-1.0
, which is the default value.
Creating a token lookup index (node label or relationship type lookup index) can be done with the CREATE LOOKUP INDEX
command.
Note that the index name must be unique.
CREATE LOOKUP INDEX [index_name] [IF NOT EXISTS]
FOR (n)
ON EACH labels(n)
Token lookup indexes have only one index provider available, token-lookup-1.0
, and no supported index configuration.
Examples
Create a node label lookup index
Create a relationship type lookup index
Create a token lookup index only if it does not already exist
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:
Creating a node label lookup index
CREATE LOOKUP INDEX node_label_lookup_index FOR (n) ON EACH labels(n)
Create a relationship type lookup index
The following statement will create a named relationship type lookup index on all relationships with any relationship type.
Creating a relationship type lookup index
CREATE LOOKUP INDEX rel_type_lookup_index FOR ()-[r]-() ON EACH type(r)
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.
Creating a node label lookup index with 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.
Failure to create an already existing index
Failure to create an index with the same name as an already existing index
Failure to create an index when a constraint already exists
Failure to create an index with the same name as an already existing constraint
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.
Creating a duplicated index
CREATE INDEX bookTitleIndex FOR (book:Book) ON (book.title)
In this case the index can not be created because it already exists.
Error message
There already exists an index (:Book {title}).
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.
Creating an index with a duplicated name
CREATE INDEX indexOnBooks FOR (book:Book) ON (book.numberOfPages)
In this case the index can’t be created because there already exists an index with the given name.
Error message
There already exists an index called 'indexOnBooks'.
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.
Creating a range index on same schema as existing index-backed constraint
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.
Error message
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.
Creating an index with same name as an existing constraint
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.
Error message
There already exists a constraint called 'bookRecommendations'.
SHOW [ALL \| FULLTEXT \| LOOKUP \| POINT \| RANGE \| TEXT] INDEX[ES]
[YIELD { * \| field[, ...] } [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]
[WHERE expression]
[RETURN field[, ...] [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]
More details about the syntax descriptions can be found here.
This command will produce a table with the following columns:
Table 1. List indexes output
Name of the index (explicitly set by the user or automatically assigned). Default Output
STRING
state
Current state of the index. Default Output
STRING
populationPercent
% of index population. Default Output
FLOAT
The IndexType of this index (FULLTEXT
, LOOKUP
, POINT
, RANGE
, or TEXT
). Default Output
STRING
entityType
Type of entities this index represents (nodes or relationship). Default Output
STRING
labelsOrTypes
The labels or relationship types of this index. Default Output
LIST OF STRING
properties
The properties of this index. Default Output
LIST OF STRING
indexProvider
The index provider for this index. Default Output
STRING
owningConstraint
The name of the constraint the index is associated with or null
if the index is not associated with any constraint. Default Output
STRING
lastRead
The last time the index was used for reading.
Returns null
if the index has not been read since trackedSince
, or if the statistics are not tracked.
Default Output
Introduced in 5.8
DATETIME
readCount
The number of read queries that have been issued to this index since trackedSince
, or null
if the statistics are not tracked. Default Output
Introduced in 5.8
INTEGER
trackedSince
The time when usage statistics tracking started for this index, or null
if the statistics are not tracked.
Introduced in 5.8
DATETIME
options
The options passed to CREATE
command.
failureMessage
The failure description of a failed index.
STRING
createStatement
Statement used to create the index.
STRING
The command SHOW INDEXES
returns only the default output.
For a full output use the optional YIELD
command.
Full output: SHOW INDEXES YIELD *
.
Listing indexes also allows for WHERE
and YIELD
clauses to filter the returned rows and columns.
Listing indexes require the SHOW INDEX
privilege.
Examples
Listing all indexes
Listing indexes with filtering
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 *
.
Showing all indexes
SHOW INDEXES
Result
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 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 |
| 13 | "example_index" | "ONLINE" | 100.0 | "RANGE" | "NODE" | ["Book"] | ["title"] | "range-1.0" | NULL | 2023-04-10T15:41:44.537Z | 2 |
| 14 | "indexOnBooks" | "ONLINE" | 100.0 | "TEXT" | "NODE" | ["Label1"] | ["prop1"] | "text-2.0" | NULL | NULL | 0 |
| 11 | "node_label_lookup_index" | "ONLINE" | 100.0 | "LOOKUP" | "NODE" | NULL | NULL | "token-lookup-1.0" | NULL | 2023-04-13T08:11:15.537Z | 10 |
| 8 | "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 |
| 5 | "node_text_index_nickname" | "ONLINE" | 100.0 | "TEXT" | "NODE" | ["Person"] | ["nickname"] | "text-2.0" | NULL | 2023-04-13T11:41:44.537Z | 2 |
| 10 | "point_index_with_config" | "ONLINE" | 100.0 | "POINT" | "NODE" | ["Label"] | ["prop2"] | "point-1.0" | NULL | NULL | 0 |
| 9 | "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 |
| 6 | "rel_text_index_name" | "ONLINE" | 100.0 | "TEXT" | "RELATIONSHIP" | ["KNOWS"] | ["interest"] | "text-2.0" | NULL | 2023-04-01T10:40:44.537Z | 3 |
| 12 | "rel_type_lookup_index" | "ONLINE" | 100.0 | "LOOKUP" | "RELATIONSHIP" | NULL | NULL | "token-lookup-1.0" | NULL | 2023-04-12T21:41:44.537Z | 7 |
| 7 | "text_index_with_indexprovider" | "ONLINE" | 100.0 | "TEXT" | "RELATIONSHIP" | ["TYPE"] | ["prop1"] | "text-2.0" | NULL | NULL | 0 |
| 15 | "uniqueBookIsbn" | "ONLINE" | 100.0 | "RANGE" | "NODE" | ["Book"] | ["isbn"] | "range-1.0" | "uniqueBookIsbn" | 2023-04-13T11:41:44.692Z | 6 |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
15 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 indexes with filtering
One way of filtering the output from SHOW INDEXES
by index type is the use of type keywords, listed in the syntax description.
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.
Showing range indexes
SHOW RANGE INDEXES WHERE owningConstraint IS NULL
Result
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 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 |
| 13 | "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 |
| 2 | "rel_range_index_name" | "ONLINE" | 100.0 | "RANGE" | "RELATIONSHIP" | ["KNOWS"] | ["since"] | "range-1.0" | NULL | 2023-04-12T10:41:44.692Z | 5 |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
5 rows
This will only return the default output columns.
To get all columns, use:
SHOW RANGE INDEXES YIELD * WHERE owningConstraint IS NULL
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]
More details about the syntax descriptions can be found here.
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.
Dropping an index requires the DROP INDEX
privilege.
Examples
Drop an index
Drop a non-existing index
Drop an index
The following statement will attempt to drop the index named example_index
.
Dropping an index
DROP INDEX example_index
If an index with that name exists it is removed, if not the command fails.
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
.
Dropping an index with 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.
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.
With IF NOT EXISTS
, 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.
CREATE [RANGE] INDEX [index_name] [IF NOT EXISTS]
FOR ()-"["r:TYPE_NAME"]"-()
ON (r.propertyName_1[,
r.propertyName_2,
r.propertyName_n])
[OPTIONS "{" option: value[, ...] "}"]
Description
Create a range index on relationships, either on a single property or composite.
Index provider can be specified using the OPTIONS
clause.
There is only one available index provider for this index.
CREATE TEXT INDEX [index_name] [IF NOT EXISTS]
FOR ()-"["r:TYPE_NAME"]"-()
ON (r.propertyName)
[OPTIONS "{" option: value[, ...] "}"]
CREATE POINT INDEX [index_name] [IF NOT EXISTS]
FOR ()-"["r:TYPE_NAME"]"-()
ON (r.propertyName)
[OPTIONS "{" option: value[, ...] "}"]
The 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.
SHOW [ALL | FULLTEXT | LOOKUP | POINT | RANGE | TEXT] INDEX[ES]
[YIELD { * | field[, ...] } [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]
[WHERE expression]
[RETURN field[, ...] [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]
Creating an index requires the CREATE INDEX
privilege,
while dropping an index requires the DROP INDEX
privilege and
listing indexes require the SHOW INDEX
privilege.
Planner hints and the USING keyword describes how to make the Cypher planner use specific indexes (especially in cases where the planner would not necessarily have used them).
If there is any equality check
and list membership check
predicates,
they need to be for the first properties defined by the index.
There can be up to one range search
or prefix search
predicate.
There can be any number of existence check
predicates.
Any predicate after a range search
, prefix search
or existence check
predicate has to be an existence check
predicate.
The suffix search
(ENDS WITH
) and substring search
(CONTAINS
) predicates can utilize the index as well.
However, they are always planned as an existence check and a filter and any predicates following after will therefore also be planned as such.
with filters on n.prop4 < 'e'
and n.prop5 = true
, since n.prop3
has a range search
predicate.
And an index on nodes with :Label(prop1,prop2)
with predicates:
WHERE n.prop1 ENDS WITH 'x' AND n.prop2 = false
will be planned as:
WHERE n.prop1 IS NOT NULL AND n.prop2 IS NOT NULL
with filters on n.prop1 ENDS WITH 'x'
and n.prop2 = false
, since n.prop1
has a suffix search
predicate.
Composite indexes require predicates on all properties indexed.
If there are predicates on only a subset of the indexed properties, it will not be possible to use the composite index.
To get this kind of fallback behavior, it is necessary to create additional indexes on the relevant sub-set of properties or on single properties.
Join us for the biggest graph community conference dedicated to learning how to integrate graph technologies into ML and dev projects.
Save your spot
© Neo4j, Inc.
Terms | Privacy | Sitemap
Neo4j®, Neo Technology®, Cypher®, Neo4j® Bloom™ and
Neo4j® Aura™ are registered trademarks
of Neo4j, Inc. All other marks are owned by their respective companies.
US: 1-855-636-4532
Sweden +46 171 480 113
UK: +44 20 3868 3223
France: +33 (0) 1 88 46 13 20