Skip to main content
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

  • valueMap with no list returns every stored property plus $id and $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.
  • project omits a property the row does not have. An expression that reads a missing property sees null.

Computed fields

Pass expression projections to project to compute fields. This request returns each line item’s sku and price times quantity:
Expressions read a property (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, and div always return an f64, so 1 + 2 returns 3.0.
  • A missing, null, or non-numeric operand fails the whole query with invalid_query. Filter those rows out first, for example with isNotNull.
  • modulo takes 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:
Cypher has no 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:
The same pattern keeps $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:
The response holds "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 null group.
  • aggregateBy reads i64, f64, and f32 values and numeric strings, and skips everything else, so AggregateFunction.Count counts numeric values, not rows. Use count() to count rows.
  • Min and Max with no numeric values return 0.0, like a real zero. Check count() 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 distinct only 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.