# Sum of unique ids

**URL:** <https://discuss.elastic.co/t/sum-of-unique-ids/134065>\
**Category:** Elasticsearch\
**Created:** [May 31, 2018, 1:44pm UTC](https://discuss.elastic.co/t/sum-of-unique-ids/134065 "2018-05-31T13:44:38Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [June 4, 2018, 2:04pm UTC](https://discuss.elastic.co/t/sum-of-unique-ids/134065/5 "2018-06-04T14:04:48Z")

</div>

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, a `max` (or `min`) 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 this `sum_bucket` will point to the `max` metric and sum them all up.

---

_[View the full topic](https://discuss.elastic.co/t/sum-of-unique-ids/134065)._
