13.1. Indexes

13.1.1. Create index on a label
13.1.2. Drop index on a label
13.1.3. Use index

Cypher allows the creation of indexes over a property for all nodes that have a given label. These indexes are automatically managed and kept up to date by the database whenever the graph is changed.

13.1.1. Create index on a label

To create an index on a property for all nodes that have a label, use CREATE INDEX ON. Note that the index is not immediately available, but will be created in the background. See Section 3.7.1, “Indexes” for details.

Query. 

CREATE INDEX ON :Person(name)

Result

Indexes added: 1

(empty result)


Try this query live. create (_0 {`name`:"A"}) create (_1 {`name`:"root"}) create (_2 {`name`:"B"}) create (_3 {`name`:"C"}) create _0-[:`KNOWS`]->_3 create _1-[:`X`]->_0 create _1-[:`X`]->_2 create _1-[:`X`]->_3 create index on :Person(name)

13.1.2. Drop index on a label

To drop an index on all nodes that have a label, use the DROP INDEX clause.

Query. 

DROP INDEX ON :Person(name)

Result

Indexes removed: 1

(empty result)


Try this query live. create (_0 {`name`:"A"}) create (_1 {`name`:"root"}) create (_2 {`name`:"B"}) create (_3 {`name`:"C"}) create _0-[:`KNOWS`]->_3 create _1-[:`X`]->_0 create _1-[:`X`]->_2 create _1-[:`X`]->_3 drop index on :Person(name)

13.1.3. Use index

There is usually no need to specify which indexes to use in a query, Cypher will figure that out by itself. For example the query below will use the Person(name) index, if it exists. If you for some reason want to hint to specific indexes, see Section 9.7, “Using”.

Query. 

MATCH (n:Person { name: 'Andres' })
RETURN n

Result

n
0 row

(empty result)


Try this query live. create (_0 {`name`:"A"}) create (_1 {`name`:"root"}) create (_2 {`name`:"B"}) create (_3 {`name`:"C"}) create _0-[:`KNOWS`]->_3 create _1-[:`X`]->_0 create _1-[:`X`]->_2 create _1-[:`X`]->_3 match (n:Person {name: 'Andres'}) return n

Asking questions

Here's where to ask to get the best answers to your Neo4j questions:

  • Having trouble running an example from the manual? First make sure that you're using the same version of Neo4j as the manual was built for! There's a dropdown on all pages that lets you switch to a different version.
  • Something doesn't work as expected with Neo4j? The stackoverflow.com neo4j tag is an excellent place for this!
  • Found a bug? Then please report and track it using the GitHub Neo4j Issues page. Note however, that you can report documentation bugs using the Disqus thread below as well.
  • Have a data modeling question or want to participate in discussions around Neo4j and graphs? The Neo4j Google Group is a great place for this.
  • Is 140 characters enough for your question? Then obviously Twitter is an option. There's lots of #neo4j activity there.
  • Have a question on the content of this page or missing something here? Then you're all set, use the discussion thread below. Please post any comments or suggestions regarding the documentation right here!