# Comparing Two Aggregate Buckets

**URL:** https://discuss.elastic.co/t/comparing-two-aggregate-buckets/274663
**Category:** Elasticsearch
**Created:** [June 1, 2021, 3:59pm UTC](https://discuss.elastic.co/t/comparing-two-aggregate-buckets/274663 "2021-06-01T15:59:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![gshanklin](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@gshanklin](https://discuss.elastic.co/u/gshanklin)
#### Post date: [June 1, 2021, 3:59pm UTC](https://discuss.elastic.co/t/comparing-two-aggregate-buckets/274663/1 "2021-06-01T15:59:42Z")

</div>

Hello,

I am having a difficult time trying to compare the results of two aggerates. More specifically, I want to find unique "keys" between two aggerate buckets. For example, I have the two aggregates on the sample web logs data:

Aggregate 1:

```auto
GET /kibana_sample_data_logs/_search
{
  "size": 0, 
  "query": {
    "match_phrase": {
      "agent": "Mozilla/4.0"
    }
  }, 
  "aggs": {
    "IPs": {
      "terms": { 
        "field": "clientip"
      }
    }
  }
}

```

Aggregate 2:

```auto
GET /kibana_sample_data_logs/_search
{
  "size": 0, 
  "query": {
    "match_phrase": {
      "agent": "Mozilla/5.0"
    }
  }, 
  "aggs": {
    "IPs": {
      "terms": { 
        "field": "clientip"
      }
    }
  }
}

```

With the resulting buckets, is there a way to create a third aggregate of IPs that are in the first aggregate but not the second or visa-versa? Preferably in a single API request?

I have tried to use sub-aggregations and scripts but not made any progress.

Thanks!

---

<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: [June 29, 2021, 4:00pm UTC](https://discuss.elastic.co/t/comparing-two-aggregate-buckets/274663/2 "2021-06-29T16:00:00Z")

</div>

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