Indexes & Constraints

CREATE INDEX

-- Single property index
CREATE INDEX idx_person_name FOR (n:Person) ON (n.name)

-- Composite index
CREATE INDEX idx_person_city_age FOR (n:Person) ON (n.city, n.age)

-- Index on document collection
CREATE INDEX idx_orders_status FOR COLLECTION orders ON (status)

Constraints

-- Unique constraint
CREATE CONSTRAINT uniq_email FOR (n:Person) REQUIRE n.email IS UNIQUE

-- Composite unique constraint
CREATE CONSTRAINT uniq_tenant_user FOR (n:Account)
  REQUIRE (n.tenant_id, n.username) IS UNIQUE

Management

-- Drop an index
DROP INDEX idx_person_name

-- Drop a constraint
DROP CONSTRAINT uniq_email

-- List indexes
SHOW INDEXES

-- List constraints
SHOW CONSTRAINTS

Index Types

TypeDescription
B+ treeDefault. Supports equality, range, and prefix queries
UniqueB+ tree with uniqueness enforcement
CompositeMulti-property B+ tree index
Full-textText search with tokenization
SpatialGeographic point indexing