Bucket script aggregation
/ Bucket_script, / AggregationBucket script aggregation #
A parent pipeline aggregation computing arithmetic on a bucket’s own
metrics — the script references sibling metrics by name through
params and its result becomes a new per-bucket value. It is the
SQL SELECT a / b AS c of the aggregation world: one derived column,
evaluated once per bucket over values the bucket already holds.
"avg_order": {
"bucket_script": {
"buckets_path": { "r": "revenue", "n": "orders" },
"script": "params.r / params.n"
}
}
How it works #
bucket_script is declared inside the multi-bucket aggregation it
decorates, next to the metrics it consumes. After the buckets are
built, the engine resolves each named path against every bucket,
binds the numbers into the script’s scope, evaluates the script once,
and inserts its result under the pipeline’s own name — the
response shape buckets[i].avg_order.value.