Skip to main content
Aggregations let you compute analytics over your indexed data — metrics like averages, sums, and statistics, as well as bucket-based groupings like terms, ranges, and histograms. Use the SEARCH.AGGREGATE command to run aggregations. They are useful when you want to answer questions like:
  • “What is the average price?”
  • “How many unique users do we have?”
  • “How many orders fall into each price range?”
  • “How does traffic change per hour/day?”
  • “How can I page through every category and price-range combination?”
Aggregation requests have two phases:
  1. Document selection: Optional filter selects which documents participate.
  2. Aggregation computation: the selected set is reduced into metric values and/or buckets.
Each aggregation is defined with an alias (the key you choose for the result) and an operator that specifies what to compute.

Response Format

Filtering

Use filter to restrict which documents participate in the aggregation. Filtering uses the same query syntax as queries.

Multiple Aggregations in One Request

You can compute multiple top-level aggregations in one call by defining multiple aliases under aggregations. Each alias is computed against the same filtered document set.

Nested Aggregations

Bucket operators can include sub-aggregations via $aggs, so you can compute per-bucket metrics.
  • $terms, $range, $histogram, $dateHistogram, and $composite support nested $aggs.
  • $facet does not support nested $aggs.
  • Metric operators do not support nested $aggs.

Operator Families

Metric Aggregations

Metric aggregations return numeric summaries. See the metric overview. By default, $sum returns 0 when no values are collected — either no documents match, or the matching documents all have a missing/null value for the field and no missing fallback is set. Set nullIfNoMatch: true to return null for that case. This lets you distinguish it from a real sum of zero.

Bucket Aggregations

Bucket aggregations partition documents into groups. See the bucket overview.