Skip to main content
Bucket aggregations group matching documents into buckets. Use bucket aggregations when you want segmented analytics (for example by category, price tier, or time window).

Available Operators

Input Format

Most bucket operators take an object with a field property and operator-specific parameters. $composite instead takes a sources array, and each source specifies its own field. $terms — group by distinct values:
$range — custom range buckets:
$histogram — fixed numeric intervals:
$dateHistogram — fixed time intervals:
$composite — paginated buckets across several sources:

Behavior Notes

  • Bucket operators can contain nested $aggs for per-bucket metrics.
  • $terms, $range, $histogram, $dateHistogram, and $composite support nested $aggs.
  • $facet does not support nested $aggs and cannot be used as a sub-aggregation.

Related topics

Overview