# Comparison of two aggregation results

**URL:** https://discuss.elastic.co/t/comparison-of-two-aggregation-results/289659
**Category:** Elasticsearch
**Tags:** vega, eql-elastic-query-language
**Created:** [November 19, 2021, 6:19am UTC](https://discuss.elastic.co/t/comparison-of-two-aggregation-results/289659 "2021-11-19T06:19:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Nikita95](https://avatars.discourse-cdn.com/v4/letter/n/c89c15/32.png) [@Nikita95](https://discuss.elastic.co/u/Nikita95)
#### Post date: [November 19, 2021, 6:19am UTC](https://discuss.elastic.co/t/comparison-of-two-aggregation-results/289659/1 "2021-11-19T06:19:08Z")

</div>

Hi everyone!

I'm new to elastic. The question arises, how can I compare two aggregation results and output the number of matches and differences.

```auto
{
  "size": 0, 
  "aggs": {
    "list_ids_in_current_range": {
      "range": {
        "field": "time_start",
        "ranges": [
          {
            "from": 1634342400000,
            "to": 1637107200000
          }
        ]
      },
      "aggs": {
        "ids": {
          "terms": {
            "field": "id.keyword",
            "size": 2147483647
          }
        }
      }
    },
    "list_existed_ids":{
      "range": {
        "field": "time_start",
        "ranges": [
          {
            "to": 1634342400000
          }
        ]
      },
      "aggs": {
        "ids": {
          "terms": {
            "field": "id.keyword",
            "size": 2147483647
          }
        }
      }
    }
  }
}

```

I have tried to aggregate using such aggregation, but it is not suitable for my case:

```auto
{"size": 0, 
  "aggs":
  {
    "ids_per_day": {
      "date_histogram": {
        "field": "time_start",
        "fixed_interval": "1d"
      },
      "aggs": {
        "distinct": {
          "cardinality": {
            "field": "id.keyword"
          }
        },
        "total_new": {
          "cumulative_cardinality": {
            "buckets_path": "distinct"
          }
        },
        "incremental_new": {
          "derivative": {
            "buckets_path": "total_new"
          }
        }
      }
    }
  }
}

```

This aggregation will be built into the custom visualization on VEGA.

---

<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: [December 17, 2021, 6:19am UTC](https://discuss.elastic.co/t/comparison-of-two-aggregation-results/289659/2 "2021-12-17T06:19:45Z")

</div>

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