Avg

Avg aggregation

/ Avg, / Aggregation

Avg aggregation #

A single-value metrics aggregation that computes the average of numeric values that are extracted from the aggregated documents. It summarizes “what does a typical matching document look like on this field” into one number — the question SQL spells AVG(price) — without fetching a single document.

How it works #

The engine walks the matching documents once, keeping a running sum and count; the result is sum / count. Nothing is estimated: the average is exact. Values are coerced to doubles as they are read — integers, floats and booleans (true = 1, false = 0) contribute, non-numeric values such as keyword strings do not.

...