# Comparing the result(sum count) of 2 aggregations - ElasticSearch

**URL:** https://discuss.elastic.co/t/comparing-the-result-sum-count-of-2-aggregations-elasticsearch/193826
**Category:** Elasticsearch
**Created:** [August 5, 2019, 3:00pm UTC](https://discuss.elastic.co/t/comparing-the-result-sum-count-of-2-aggregations-elasticsearch/193826 "2019-08-05T15:00:23Z")
**Posts on this page:** 3
**Page:** 1

<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 5, 2019, 3:00pm UTC](https://discuss.elastic.co/t/comparing-the-result-sum-count-of-2-aggregations-elasticsearch/193826/1 "2019-08-05T15:00:23Z")

</div>

Hi all,

I am relatively new to Elasticsearch and am trying to write a script that is supposed to compare two different aggregations.

For example, I have 2 sum aggregations of the same field, but calculated at 2 different time  
intervals, as shown below.

2xxCount = {

```
    "_source": {
        "includes": ["indexname", "tags"] },

 "query": {
        "bool" : {
            "must" : { "match" : { "tags" : "sample_tag" } },
            "must" : {"range" : {"logdate" : {"gte": "now", "lte": "now-1d/d"}}}              
                }
       },       
 "size" : 0,    
 "aggs" : {
          "total_2xx_count_today": {"sum" : { "field": "2xx_count" }}
           }       

```

}

2xxLast2Days = {

```
    "_source": {
        "includes": ["indexname", "tags"] },

 "query": {
        "bool" : {
            "must" : { "match" : { "tags" : "sample_tag" } },
            "must" : {"range" : {"logdate" : {"gte": "now", "lte": "now-2d/d"}}}              
                }
       },       
 "size" : 0,    
 "aggs" : {
          "total_2xx_count_yesterday": {"sum" : { "field": "2xx_count" }}
           }       

```

}

Note that these aggregations are in 2 different body (2xxCount and 2xxLast2Days).

This returns the count of the 2xx calculated during those 2 time intervals. Is there any way I can compare the result of these 2 aggregations? Ideally, what I am trying to do is check if the count is increasing on specific days compared to other days.

Any help is appreciated!

---

<div class="post-metadata">

### Author: ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)
#### Post date: [August 7, 2019, 3:39am UTC](https://discuss.elastic.co/t/comparing-the-result-sum-count-of-2-aggregations-elasticsearch/193826/2 "2019-08-07T03:39:45Z")

</div>

Hi @Kaushik123,

You can try like in the example bellow to have only one request and 2 aggregations results... check the doc it will be more easy to understand:

[https://www.elastic.co/guide/en/elasticsearch/reference/7.3/search-aggregations-bucket-filters-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/search-aggregations-bucket-filters-aggregation.html)

---

<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: [September 4, 2019, 3:39am UTC](https://discuss.elastic.co/t/comparing-the-result-sum-count-of-2-aggregations-elasticsearch/193826/3 "2019-09-04T03:39:50Z")

</div>

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