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
| Type | Description |
|---|
| B+ tree | Default. Supports equality, range, and prefix queries |
| Unique | B+ tree with uniqueness enforcement |
| Composite | Multi-property B+ tree index |
| Full-text | Text search with tokenization |
| Spatial | Geographic point indexing |