# How to calculate two aggregations on same field within the same body?

**URL:** https://discuss.elastic.co/t/how-to-calculate-two-aggregations-on-same-field-within-the-same-body/193889
**Category:** Elasticsearch
**Created:** [August 5, 2019, 9:50pm UTC](https://discuss.elastic.co/t/how-to-calculate-two-aggregations-on-same-field-within-the-same-body/193889 "2019-08-05T21:50:58Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![Kaushik123](https://avatars.discourse-cdn.com/v4/letter/k/87869e/32.png) [@Kaushik123](https://discuss.elastic.co/u/Kaushik123)
#### Post date: [August 6, 2019, 5:48pm UTC](https://discuss.elastic.co/t/how-to-calculate-two-aggregations-on-same-field-within-the-same-body/193889/5 "2019-08-06T17:48:16Z")

</div>

Thanks for the reply @kumar8055,

I did not have any trouble finding the aggregations. What I am trying to understand is how I can compare 2 aggregations, when both aggregations are performed on the same field, just different time/date.

The field I am calculating on is in a index called swift-xxx. So what I am doing is creating a body with the aggregation(date/time specified in a bool query), and then calling the result as shown below.

[Queries for the 2 aggregations](https://discuss.elastic.co/t/comparing-the-result-sum-count-of-2-aggregations-elasticsearch/193826)

count = es.search(index='swift-xxx', body=2xxCount)  
print(count)

count2 = es.search(index='swift-xxx', body=2xxLast2Days)  
print(count2)

Note that these two are 2 seperate queries that result 2 seperate sum aggregations. Is there any way I can combine then into one body and compare the result - i.e. see which 2xx is greater and print it.

---

_[View the full topic](https://discuss.elastic.co/t/how-to-calculate-two-aggregations-on-same-field-within-the-same-body/193889)._
