Weighted average aggregation #
A single-value metrics aggregation that computes the weighted average of
numeric values. Each document contributes value × weight, divided by
the total weight — e.g. an average price weighted by quantity sold.
Example #
Average unit price weighted by qty (larger purchases count more):
The plain
avg of price is 27.5; quantity-weighted it is
28.125.
Parameters for weighted_avg
#
value
(Required, object)field— the numeric field whose values are averaged.weight
(Required, object)field— the numeric field used as the per-document weight.value.missing/weight.missing
(Optional, number) Value substituted for documents missing the field; a missing weight defaults the document out of the average.