Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
Creating an index is done with the `CREATE [index_type] INDEX [index_name]` command.
If no index type is specified in the create command a xref:indexes/search-performance-indexes/create-indexes.adoc#create-range-index[range index] is created.

The following index types are included in this category:

* xref:indexes/search-performance-indexes/create-indexes.adoc#create-range-index[Range indexes]
* xref:indexes/search-performance-indexes/create-indexes.adoc#create-text-index[Text indexes]
* xref:indexes/search-performance-indexes/create-indexes.adoc#create-point-index[Point indexes]
* xref:indexes/search-performance-indexes/create-indexes.adoc#create-lookup-index[Token lookup indexes]

It is recommended to give the index a name when it is created.
If the index is not explicitly named, it gets an auto-generated name.

Expand All @@ -28,8 +35,10 @@ Creating an index requires link:{neo4j-docs-base-uri}/operations-manual/current/
====

[NOTE]
====
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-range-index]]
== Create a range index
Expand Down Expand Up @@ -100,7 +109,7 @@ STARTS WITH
[[create-a-single-property-range-index-for-nodes]]
==== 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.
The following statement creates a named range index on all nodes labeled with `Person` and which have the `surname` property.

.Creating a node range index on a single property
[source, cypher]
Expand All @@ -112,7 +121,7 @@ CREATE INDEX node_range_index_name FOR (n:Person) ON (n.surname)
[[create-a-single-property-range-index-for-relationships]]
==== 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`.
The following statement creates a named range index on all relationships with relationship type `KNOWS` and property `since`.

.Creating a relationship range index on a single property
[source, cypher]
Expand All @@ -125,9 +134,9 @@ 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.
For node range indexes, only nodes with the specified label and that contain all the specified properties are 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.
The following statement creates a named composite range index on all nodes labeled with `Person` and which have both an `age` and `country` property.

.Creating a composite node range index on multiple properties
[source, cypher]
Expand All @@ -140,9 +149,9 @@ 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.
For relationship range indexes, only relationships with the specified type and that contain all the specified properties are 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.
The following statement creates a named composite range index on all relationships labeled with `PURCHASED` and which have both a `date` and `amount` property.

.Creating a composite relationship range index on multiple properties
[source, cypher]
Expand All @@ -154,7 +163,7 @@ CREATE INDEX composite_range_rel_index_name FOR ()-[r:PURCHASED]-() ON (r.date,
[[create-a-range-index-by-param]]
==== Create a range index using a parameter

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.
The following statement creates a named range index on all nodes with a `Person` label and a `firstname` property using a parameter for the index name.

.Parameters
[source, parameters]
Expand Down Expand Up @@ -183,8 +192,8 @@ 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.
Instad an informational notification is returned.
The index is not created if there already exists an index with the same schema and type, same name or both.
Instead an informational notification is returned.

.Notification
[source]
Expand Down Expand Up @@ -297,7 +306,7 @@ For more information, see xref:indexes/search-performance-indexes/using-indexes.
[[create-a-node-text-index]]
==== 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.
The following statement creates a named text index on all nodes labeled with `Person` and which have the `nickname` `STRING` property.

.Creating a node text index on a single property
[source, cypher]
Expand All @@ -309,7 +318,7 @@ CREATE TEXT INDEX node_text_index_nickname FOR (n:Person) ON (n.nickname)
[[create-a-relationship-text-index]]
==== 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`.
The following statement creates a named text index on all relationships with relationship type `KNOWS` and `STRING` property `interest`.

.Creating a relationship text index on a single property
[source, cypher]
Expand All @@ -321,7 +330,7 @@ CREATE TEXT INDEX rel_text_index_name FOR ()-[r:KNOWS]-() ON (r.interest)
[[create-a-text-index-by-param]]
==== Create a text index using a parameter

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.
The following statement creates a named text index on all nodes with the `Person` label the `favoriteColor` `STRING` property using a parameter for the index name.

.Parameters
[source, parameters]
Expand All @@ -343,15 +352,15 @@ CREATE TEXT INDEX $name FOR (n:Person) ON (n.favoriteColor)

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.
The following statement attempts to create a named text index on all nodes labeled with `Person` and which have the `nickname` `STRING` property.

.Creating a text index with `IF NOT EXISTS`
[source, cypher]
----
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.
Note that the index is not created if there already exists an index with the same schema and type, same name or both.
Instead, an informational notification is returned.

.Notification
Expand Down Expand Up @@ -424,7 +433,7 @@ To learn more about the spatial data types supported by Cypher, see the page abo
[[create-a-node-point-index]]
==== 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.
The following statement creates a named point index on all nodes labeled with `Person` and which have the `sublocation` `POINT` property.

.Creating a node point index on a single property
[source, cypher]
Expand All @@ -436,7 +445,7 @@ CREATE POINT INDEX node_point_index_name FOR (n:Person) ON (n.sublocation)
[[create-a-relationship-point-index]]
==== 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`.
The following statement creates a named point index on all relationships with relationship type `STREET` and `POINT` property `intersection`.

.Creating a relationship point index on a single property
[source, cypher]
Expand All @@ -448,7 +457,7 @@ CREATE POINT INDEX rel_point_index_name FOR ()-[r:STREET]-() ON (r.intersection)
[[create-a-point-index-by-param]]
==== Create a point index using a parameter

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.
The following statement creates a named point index on all relationships with relationship type `STREET` and `POINT` property `coordinate` using a parameter for the index name.

.Parameters
[source, parameters]
Expand Down Expand Up @@ -477,7 +486,7 @@ 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.
Note that the index is not created if there already exists an index with the same schema and type, same name or both.
Instead, an informational notification is returned.

.Notification
Expand All @@ -504,7 +513,7 @@ The valid configuration settings are:
* `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.
The following statement creates a point index specifying the `spatial.cartesian.min` and `spatial.cartesian.max` settings.

.Creating a point index with index configuration
[source, cypher]
Expand All @@ -519,7 +528,7 @@ OPTIONS {
}
----

Note that the wgs-84 and 3D cartesian settings, which are not specified in this example, will be set with their respective default values.
Note that the wgs-84 and 3D cartesian settings, which are not specified in this example, are set with their respective default values.

[[create-lookup-index]]
== Create a token lookup index
Expand Down Expand Up @@ -587,7 +596,7 @@ Token lookup indexes improve the performance of Cypher queries and the populatio
[[create-a-node-label-lookup-index]]
==== 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:
The following statement creates a named node label lookup index on all nodes with one or more labels:

// Lookup indexes exist by default, recreating them would raise an error
.Creating a node label lookup index
Expand All @@ -605,7 +614,7 @@ Only one node label lookup index can exist at a time.
[[create-a-relationship-type-lookup-index]]
==== Create a relationship type lookup index

The following statement will create a named relationship type lookup index on all relationships with any relationship type.
The following statement creates a named relationship type lookup index on all relationships with any relationship type.

// Lookup indexes exist by default, recreating them would raise an error
.Creating a relationship type lookup index
Expand All @@ -631,7 +640,7 @@ If it is not known whether an index exists or not, add `IF NOT EXISTS` to ensure
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.
The index is not created if there already exists an index with the same schema and type, same name or both.
Instead, an informational notification is returned.

.Notification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,27 @@ The name of the index can be found using the xref:indexes/search-performance-ind
The below indexes are created in schema/indexes/create-indexes.adoc
[source, cypher, role=test-setup]
----
CREATE INDEX node_range_index_name FOR (n:Person) ON (n.surname)
CREATE INDEX rel_range_index_name FOR ()-[r:KNOWS]-() ON (r.since)
CREATE INDEX composite_range_node_index_name FOR (n:Person) ON (n.age, n.country)
CREATE INDEX composite_range_rel_index_name FOR ()-[r:PURCHASED]-() ON (r.date, r.amount)
CREATE INDEX $name FOR (n:Person) ON (n.firstname)
CREATE INDEX node_range_index_name IF NOT EXISTS FOR (n:Person) ON (n.surname)
CREATE TEXT INDEX node_text_index_nickname FOR (n:Person) ON (n.nickname)
CREATE TEXT INDEX rel_text_index_name FOR ()-[r:KNOWS]-() ON (r.interest)
CREATE TEXT INDEX $name FOR (n:Person) ON (n.favoriteColor)
CREATE TEXT INDEX node_index_name IF NOT EXISTS FOR (n:Person) ON (n.nickname)
CREATE POINT INDEX node_point_index_name FOR (n:Person) ON (n.sublocation)
CREATE POINT INDEX rel_point_index_name FOR ()-[r:STREET]-() ON (r.intersection)
CREATE POINT INDEX $name FOR ()-[r:STREET]-() ON (r.coordinate)
CREATE POINT INDEX node_point_index IF NOT EXISTS FOR (n:Person) ON (n.sublocation)
CREATE INDEX node_range_index_name FOR (n:Person) ON (n.surname);
CREATE INDEX rel_range_index_name FOR ()-[r:KNOWS]-() ON (r.since);
CREATE INDEX composite_range_node_index_name FOR (n:Person) ON (n.age, n.country);
CREATE INDEX composite_range_rel_index_name FOR ()-[r:PURCHASED]-() ON (r.date, r.amount);
CREATE INDEX range_index_param FOR (n:Person) ON (n.firstname);
CREATE TEXT INDEX node_text_index_nickname FOR (n:Person) ON (n.nickname);
CREATE TEXT INDEX rel_text_index_name FOR ()-[r:KNOWS]-() ON (r.interest);
CREATE TEXT INDEX text_index_param FOR (n:Person) ON (n.favoriteColor);
CREATE POINT INDEX node_point_index_name FOR (n:Person) ON (n.sublocation);
CREATE POINT INDEX rel_point_index_name FOR ()-[r:STREET]-() ON (r.intersection);
CREATE POINT INDEX point_index_param FOR ()-[r:STREET]-() ON (r.coordinate);
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]
}
}
CREATE LOOKUP INDEX node_label_lookup_index FOR (n) ON EACH labels(n)
CREATE LOOKUP INDEX rel_type_lookup_index FOR ()-[r]-() ON EACH type(r)
CREATE LOOKUP INDEX node_label_lookup IF NOT EXISTS FOR (n) ON EACH labels(n)
CREATE INDEX example_index FOR (n:Book) ON (n.title)
CREATE INDEX bookTitleIndex FOR (book:Book) ON (book.title)
CREATE TEXT INDEX indexOnBooks FOR (b:Label1) ON (b.prop1)
CREATE INDEX indexOnBooks FOR (book:Book) ON (book.numberOfPages)
CREATE CONSTRAINT uniqueBookIsbn FOR (book:Book) REQUIRE (book.isbn) IS UNIQUE
CREATE INDEX bookIsbnIndex FOR (book:Book) ON (book.isbn)
CREATE CONSTRAINT bookRecommendations FOR (book:Book) REQUIRE (book.recommend) IS NOT NULL
CREATE INDEX bookRecommendations FOR (book:Book) ON (book.recommendations)
};
CREATE INDEX example_index FOR (n:Book) ON (n.title);
CREATE TEXT INDEX indexOnBooks FOR (b:Label1) ON (b.prop1);
CREATE CONSTRAINT uniqueBookIsbn FOR (book:Book) REQUIRE (book.isbn) IS UNIQUE;
CREATE CONSTRAINT bookRecommendations FOR (book:Book) REQUIRE (book.recommend) IS NOT NULL;
----
////

Expand All @@ -54,7 +44,9 @@ With `IF EXISTS`, no error is thrown and nothing happens should the index not ex
Instead, an informational notification is returned detailing that the index does not exist.

[NOTE]
====
Dropping an index requires link:{neo4j-docs-base-uri}/operations-manual/current/database-administration/authentication-authorization/database-administration/#access-control-database-administration-index[the `DROP INDEX` privilege].
====


[[drop-indexes-examples]]
Expand All @@ -69,7 +61,7 @@ Dropping an index requires link:{neo4j-docs-base-uri}/operations-manual/current/
[[drop-an-index]]
=== Drop an index

The following statement will attempt to drop the index named `example_index`.
The following statement attempts to drop the index named `example_index`.

.Dropping an index
[source, cypher]
Expand All @@ -83,7 +75,7 @@ If an index with that name exists it is removed, if not the command fails.
[[drop-an-index-by-param]]
==== Drop an index using a parameter

The following statement will attempt to drop the index named `range_index_param` using a parameter for the index name.
The following statement attempts to drop the index named `range_index_param` using a parameter for the index name.

.Parameters
[source, parameters]
Expand Down Expand Up @@ -119,7 +111,7 @@ DROP INDEX uniqueBookIsbn
Unable to drop index: Index belongs to constraint: `uniqueBookIsbn`
----

Dropping the index-backed constraint will also remove the backing index.
Dropping the index-backed constraint also removes the backing index.
For more information, see xref:constraints/managing-constraints.adoc#drop-constraint[Drop a constraint by name].


Expand All @@ -128,7 +120,7 @@ For more information, see xref:constraints/managing-constraints.adoc#drop-constr

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`.
The following statement attempts to drop the index named `missing_index_name`.

.Dropping an index with `IF EXISTS`
[source, cypher]
Expand Down
Loading