Guide
Projection operations turn a traversal stream into the response shape your application
needs. They are terminal: no step can follow a projection.
Choose a projection
Rename fields
Field rules
valueMapwith no list returns every stored property plus$idand$label, never$from,$to,$distance, or$score; list those to return them.valueMap([...])returns the listed keys that are present; a row with none returns{}.values([...])is the same, but drops rows with none of the keys.projectomits a property the row does not have. An expression that reads a missing property seesnull.
Computed fields
Pass expression projections toproject to compute fields. This request returns each
line item’s sku and price times quantity:
Expr.prop), a literal (Expr.val), a parameter
(Expr.param), the element ID (Expr.id), or the current time (Expr.timestamp in
epoch milliseconds). They combine with add, sub, mul, div, modulo (Mod in
Go), and neg. Expr.case picks the first branch whose predicate matches, or null
without an else branch.
add,sub,mul, anddivalways return anf64, so1 + 2returns3.0.- A missing,
null, or non-numeric operand fails the whole query withinvalid_query. Filter those rows out first, for example withisNotNull. modulotakes integers only and fails on a zero divisor.
Project correlated bindings
projectBindings / project_bindings emits one row per traversal result, reading
values from names captured earlier with bind.
projectDistinctBindings / project_distinct_bindings also removes duplicate
projected tuples.
When alternative branches bind different names, a row carries only the bindings its
own path set. Use coalesce to take the first binding that is present. This request
maps each service to a workload ID, whichever branch found it:
UNION (see the
Cypher guide), so the
Cypher tab gives each union branch its own row through UNWIND, runs that branch as
an OPTIONAL MATCH, and drops rows where the branch found nothing.
Keep search scores after traversing
$distance and $score are gone once the traversal leaves the hit, and a projection
cannot run first because it ends the traversal. Bind the hit and read the score from the
binding. This request returns the ten closest documents with distance and author:
$score from a text search.
Each row pairs one hit with one author, so a document with no AUTHORED_BY edge
produces no row. To keep it, bind the author in an optional step,
optional(sub().out("AUTHORED_BY").bind("author")), and project
BindingProjection.binding("author", "name", "author"); the document then comes back
without an author field. Do not use current here: with no author, the current
element is still the document, so current("name", ...) returns the document’s name.
Aggregate
Aggregates run inside the transaction. This request counts orders per status and sums their totals:"by_status": [{"status": "paid", "count": 12}, {"status": "refunded", "count": 2}]
and "revenue": [{"total_Sum": 1840.5}].
- Groups come back sorted by value. Rows without the property form a
nullgroup. aggregateByreadsi64,f64, andf32values and numeric strings, and skips everything else, soAggregateFunction.Countcounts numeric values, not rows. Usecount()to count rows.MinandMaxwith no numeric values return0.0, like a real zero. Checkcount()when that matters.
Keep responses small
- Project only fields the caller uses.
- Bind a search hit before traversing away from it if the response needs its score; see Keep search scores after traversing.
- Use aggregates in the engine instead of returning full rows for client-side counting.
- Add
distinctonly when duplicate elimination is semantically required.
Next steps
Bindings and branches
Preserve row-local values across optional and union operations.
Vector search
Create an index, rank vector hits, and preserve distance metadata.