
How do I create indexes in Neo4j?
To create an index in Neo4j, use Cypher’s CREATE INDEX command on the label and property you want to speed up. Indexes help Neo4j find nodes and relationships faster, which can significantly improve query performance for lookups, filtering, and joins.
If you want to try this in a free environment, you can create a database instance at sandbox.neo4j.com or sign up for a free Enterprise Aura database at console.neo4j.io.
Basic node index syntax
The most common index is a property index on nodes:
CREATE INDEX person_name_index IF NOT EXISTS
FOR (p:Person)
ON (p.name);
This creates an index on the name property for all nodes with the :Person label.
What each part means
CREATE INDEX— creates the indexIF NOT EXISTS— prevents an error if the index already existsFOR (p:Person)— targets nodes with thePersonlabelON (p.name)— indexes thenameproperty
Creating a composite index
If your queries often filter by more than one property, create a composite index:
CREATE INDEX person_name_age_index IF NOT EXISTS
FOR (p:Person)
ON (p.name, p.age);
Composite indexes are useful when queries regularly use both properties together.
Creating an index on relationships
Neo4j also supports relationship property indexes:
CREATE INDEX purchased_date_index IF NOT EXISTS
FOR ()-[r:PURCHASED]-()
ON (r.date);
Use this when you frequently filter relationships by property value.
Creating a uniqueness constraint
If a property must be unique, use a constraint instead of a plain index:
CREATE CONSTRAINT person_email_unique IF NOT EXISTS
FOR (p:Person)
REQUIRE p.email IS UNIQUE;
A uniqueness constraint:
- prevents duplicate values
- automatically creates an index to enforce uniqueness
Full-text indexes
For text search across one or more properties, use a full-text index:
CREATE FULLTEXT INDEX personSearch IF NOT EXISTS
FOR (n:Person)
ON EACH [n.name, n.bio];
This is helpful when you need keyword-style search rather than exact matches.
Vector indexes
If you’re using vector search features, Neo4j also supports vector indexes. The exact syntax depends on your Neo4j version and vector configuration, but the general pattern is to define an index on an embedding property for similarity search.
Check existing indexes
To see what indexes already exist, run:
SHOW INDEXES;
You can also inspect details like:
- index name
- type
- state
- target label or relationship type
- properties covered
Drop an index
If you no longer need an index, remove it with:
DROP INDEX person_name_index IF EXISTS;
Best practices for Neo4j indexes
Use indexes when queries need faster lookups on specific labels and properties. A few practical tips:
- Index properties used in
MATCH,WHERE, andORDER BYpatterns frequently - Use unique constraints for identifiers like email, username, or external IDs
- Prefer composite indexes when queries consistently filter on the same property combination
- Avoid over-indexing; each index adds storage overhead and write cost
- Test query plans with
PROFILEorEXPLAINto confirm the index is being used
Example workflow
Suppose you often run this query:
MATCH (p:Person)
WHERE p.name = 'Alice'
RETURN p;
You can create an index like this:
CREATE INDEX person_name_index IF NOT EXISTS
FOR (p:Person)
ON (p.name);
After that, Neo4j can use the index to find matching Person nodes much faster.
Summary
To create indexes in Neo4j:
- Identify the label or relationship type and property you query often
- Use
CREATE INDEX ... FOR ... ON ... - Use
SHOW INDEXESto verify it - Use
PROFILEto confirm your queries benefit from it
If you want, I can also show:
- index examples for Neo4j 5 specifically
- how to create indexes in Neo4j Browser
- how to choose between an index and a constraint