# How to sum fieds of collapsed results?

**URL:** <https://discuss.elastic.co/t/how-to-sum-fieds-of-collapsed-results/323617>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [January 20, 2023, 5:04pm UTC](https://discuss.elastic.co/t/how-to-sum-fieds-of-collapsed-results/323617 "2023-01-20T17:04:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![denise.castagna](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@denise.castagna](https://discuss.elastic.co/u/denise.castagna)\
**Post date:** [January 20, 2023, 5:04pm UTC](https://discuss.elastic.co/t/how-to-sum-fieds-of-collapsed-results/323617/1 "2023-01-20T17:04:54Z")

</div>

Hi,  
I need to do a sum aggregation on a collapsed result. I know that collapse does not effect on aggregation but there are other ways?

For example:

- Field1 = A, Field2 = 50, Order = 1
- Field1 = A, Field2 = 30, Order = 2
- Field1 = B, Field2 = 20, Order = 1

My query is ordered by "Order" and collapsed on "Field1", then I want to sum "Field2" of the collapsed result to obtain, in this case, the value 70.

Is it possible?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 17, 2023, 5:05pm UTC](https://discuss.elastic.co/t/how-to-sum-fieds-of-collapsed-results/323617/2 "2023-02-17T17:05:12Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
