Stage Category: REDUCE (Aggregates results)Transformation: N documents → aggregation results + optional documents
Aggregating a whole collection? Use
POST /v1/collections/{collection_identifier}/documents/aggregate. It runs the
same functions over every matching document, not just the current pipeline’s
results. It returns exact counts at any collection size, and count,
count_distinct, sum, avg, min and max stream without a row cap. Pair
it with the is_null filter operator for field-presence checks, such as
counting documents missing a from_collection ancestor across 180k+ assets.The two request bodies share group_by (an array of objects), function and
alias. The endpoint adds filters, having, unwind and range_buckets, and
calls its sort direction sort_direction where this stage uses sort_order.aggregations is required, with at least one entry. Every entry needs
function and alias. field is required for every function except count.When to Use
When NOT to Use
Parameters
Each entry in
aggregations:
A field path resolves against the document the way the Group By
stage does.
score and document_id are read directly. A bare name such as
client_id is looked up on the document, then in metadata. A dotted path such as
metadata.price walks the document.
Aggregation Functions
Configuration Examples
Output
The groups and metrics come back in the stage’s statistics:stages is keyed by the stage_name you gave the stage. output_count is 0 when
include_documents is false, because the stage consumes the documents. With
include_documents: true it equals input_count, and the documents continue to
the next stage unchanged.
Without group_by there is one entry and group is null:
Performance
Common Pipeline Patterns
Search with Facets
Analytics Pipeline
E-Commerce Product Analytics
Aggregation Details
Count
Sum / Avg / Min / Max
null.

