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
| Operator | Example | Description |
|---|---|---|
= | p.age = 30 | Equality |
<> | p.age <> 30 | Not equal |
> | p.age > 25 | Greater than |
< | p.age < 60 | Less than |
>= | p.age >= 18 | Greater or equal |
<= | p.age <= 100 | Less or equal |
CONTAINS | p.name CONTAINS 'John' | Substring match |
STARTS WITH | p.name STARTS WITH 'J' | Prefix match |
ENDS WITH | p.name ENDS WITH 'n' | Suffix match |
IN | p.city IN ['NYC', 'LA'] | In list |
NOT IN | p.city NOT IN ['SF'] | Not in list |
IS NULL | p.email IS NULL | Null check |
IS NOT NULL | p.email IS NOT NULL | Not 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
- Traversal — path finding
- Cypher Queries — WHERE clause details
- API Reference