Avg_bucket

Avg bucket aggregation

/ Avg_bucket, / Aggregation

Avg bucket aggregation #

A sibling pipeline aggregation computing the average of a metric across another aggregation’s buckets. Bucket aggregations answer “what is the revenue per day / per category / per range”; avg_bucket rolls those per-bucket numbers into one mean — “what does a typical day or category bring in” — without a second query or client-side arithmetic.

"avg_day": { "avg_bucket": { "buckets_path": "per_day>revenue" } }

How it works #

avg_bucket is declared next to the bucket aggregation it consumes (a sibling in the same aggs object) and runs after every regular aggregation has finished — after the merge, too, in a distributed search. It reads the parent’s finished buckets, collects one number per bucket, and divides their sum by their count. The result is a single-value metric ({"value": 56.25}) placed alongside the parent.

...