Ok cool, that makes things easier.
What I would do is:
-
terms
aggregation on ID-
max
metric aggregation on quantity. Because all the quantities will be the same, amax
(ormin
) will just return the value. -
sum_bucket
pipeline aggregation to add up all the quantities. Pipeline aggregations act on the result of other aggs, so thissum_bucket
will point to themax
metric and sum them all up.
-