Skip to main content
Aggregate stage showing statistical computations on search results
The Aggregate stage computes statistical aggregations across your search results, including counts, sums, averages, min/max values, and custom metrics. This is useful for analytics, faceted search, and understanding result distributions.
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.That endpoint does not take this stage’s shape. Three names differ:group_by and aggregations are both required, each with at least one entry:
Every operation needs function and alias. field is required for every function except count. count_distinct takes distinct_field instead.

When to Use

When NOT to Use

Parameters

Aggregation Types

Configuration Examples

Output Schema

Without Group By

With Group By

Histogram Output

Performance

Common Pipeline Patterns

Search with Facets

Analytics Pipeline

E-Commerce Product Analytics

Aggregation Details

Count

Counts documents. No field required.

Sum / Avg / Min / Max

Requires numeric field.

Cardinality

Counts unique values (approximate for large sets).

Percentile

Returns specified percentile values.

Histogram

Groups values into buckets.

Statistical Aggregation Examples

Statistical Output Examples

Frequency returns value counts with percentages:
Co-occurrence returns field pair counts:
Correlation returns the Pearson coefficient (-1 to 1):

Error Handling