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