Skip to main content

Filtering

Filter nodes and edges by type and properties.

Node Filtering

Get Nodes with Type Filter

MATCH (p:Person) RETURN p.name, p.age

Property Filtering with Cypher

Use Cypher's WHERE clause for property-based filtering:

MATCH (p:Person)
WHERE p.city = 'NYC'
RETURN p.name, p.age

Property Operators

OperatorExampleDescription
=p.age = 30Equality
<>p.age <> 30Not equal
>p.age > 25Greater than
<p.age < 60Less than
>=p.age >= 18Greater or equal
<=p.age <= 100Less or equal
CONTAINSp.name CONTAINS 'John'Substring match
STARTS WITHp.name STARTS WITH 'J'Prefix match
ENDS WITHp.name ENDS WITH 'n'Suffix match
INp.city IN ['NYC', 'LA']In list
NOT INp.city NOT IN ['SF']Not in list
IS NULLp.email IS NULLNull check
IS NOT NULLp.email IS NOT NULLNot null

Edge Filtering

Filter by Source/Target Node

MATCH (a:Person)-[:KNOWS]->(b:Person)
WHERE a.name = 'Alice'
RETURN b.name

Logical Operators

WHERE p.age > 25 AND p.status = 'active'
WHERE p.city = 'NYC' OR p.city = 'LA'
WHERE NOT p.archived
WHERE p.age > 18 AND (p.city = 'NYC' OR p.city = 'LA')

Creating Indexes

For O(1) property lookups on large datasets:

-- Node index
CREATE INDEX email_idx FOR (n:Person) ON (n.email)

-- Compound index
CREATE INDEX name_status_idx FOR (n:Person) ON (n.name, n.status)

-- Edge index
CREATE INDEX since_idx FOR ()-[r:KNOWS]-() ON (r.since)

Next Steps