Create An Index In Neo4j
The following is Cypher syntax for creating and dropping an index within Neo4j.
Create An Index
CREATE INDEX ON :User(email)
Create A Composite Index
CREATE INDEX ON :User(email, city)
Drop An Index
DROP INDEX ON :Person(email)
Drop A Composite Index
DROP INDEX ON :User(email, city)
Show All Indexes Within Your Neo4j Graph
What is a database index?
A database index is a data structure used to speed up the retrieval of data within your database.
Why should you use an index?
As stated above, using an index will make retrieving data that you have indexed more efficient. In large graphs, this can have a tremendous impact on the time it takes for your query to return results.
What are the downside of using an index?
Since using an index should make your queries return data faster, why not use them all of the time?
Adding an index will increase the time it takes to insert data into the graph. Having the index in place adds overhead to insert your data because the index needs to get updated for the newly added data.
If reading data as quickly as possible is important to your application, make sure you are using indexes appropriately, but remember, that will impact the speed of inserting data. Often, the positive impact an index provides on reads greatly outweighs the overhead during insert.