Skip to main content

Filtering

Filter nodes and edges by type and properties.

Node Filtering

Get Nodes with Type Filter

const people = await graph.getNodes({ filter: { nodeType: 'Person' } });

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

Get Edges by Type

const knowsEdges = await graph.getEdges({ filter: { edgeType: 'KNOWS' } });

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')

GraphQueryOptions

interface GraphQueryOptions {
filter?: {
types?: string[]; // filter by node/edge types (OR within types)
properties?: FilterProperty[]; // property key-value pair filters
};
orderBy?: IOrderBy; // sort results (field + direction)
limit?: number; // limit results
distinct?: boolean; // deduplicate values for aggregation
transaction?: GraphTransaction; // transaction context
}

// FilterProperty for property-based filtering
interface FilterProperty {
key?: string;
value?: unknown;
op?: '=' | '<>' | '>' | '<' | '>=' | '<=' | 'CONTAINS' | 'STARTS_WITH' | 'ENDS_WITH' | 'IN' | 'NOT_IN' | 'IS_NULL' | 'IS_NOT_NULL';
AND?: FilterProperty[];
OR?: FilterProperty[];
}

Creating Indexes

For O(1) property lookups on large datasets:

// Index on node property
await graph.createIndex('node', 'email');
await graph.createIndex('node', 'status');

// Index on edge property
await graph.createIndex('edge', 'since');

Next Steps