Thursday, October 29, 2020

Neo4j - Create an Index using Cypher

In Neo4j, you can create an index over a property on any node that has been given a label. Once you create an index, Neo4j will manage it and keep it up to date whenever the database is changed.


To create an index, use the CREATE INDEX ON statement. Like this:


CREATE INDEX ON :Album(Name)


Index Hints


Once an index has been created, it will automatically be used when you perform relevant queries.


However, Neo4j also allows you to enforce one or more indexes with a hint. You can create an index hint by including USING INDEX ... in your query.


So we could enforce the above index as follows:



MATCH (a:Album {Name: "Somewhere in Time"}) 

USING INDEX a:Album(Name) 

RETURN a




References:

https://www.quackit.com/neo4j/tutorial/neo4j_create_an_index_using_cypher.cfm


No comments:

Post a Comment