# Terms aggregations exclude the key of parent

**URL:** <https://discuss.elastic.co/t/terms-aggregations-exclude-the-key-of-parent/236977>\
**Category:** Elasticsearch\
**Created:** [June 13, 2020, 12:30pm UTC](https://discuss.elastic.co/t/terms-aggregations-exclude-the-key-of-parent/236977 "2020-06-13T12:30:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Steenbergen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter_steenbergen/32/22888_2.png) [@Peter\_Steenbergen](https://discuss.elastic.co/u/Peter_Steenbergen)\
**Post date:** [June 13, 2020, 12:30pm UTC](https://discuss.elastic.co/t/terms-aggregations-exclude-the-key-of-parent/236977/1 "2020-06-13T12:30:55Z")

</div>

```auto
   GET posts/_search
    {
      "size": 0,
      "aggs": {
        "hashtags": {
          "terms": {
            "field": "hashtags",
            "size": 10
          },
          "aggs": {
            "tagalongs": {
              "terms": {
                "field": "hashtags",
                "size": 10
              }
            }
          }
        }
      }
    }

```

With this query you get results with the same key as the top result. Like the following example.

```auto
    "aggregations" : {
        "hashtags" : {
          "doc_count_error_upper_bound" : 1991,
          "sum_other_doc_count" : 865940,
          "buckets" : [
            {
              "key" : "love",
              "doc_count" : 12542,
              "tagalongs" : {
                "doc_count_error_upper_bound" : 973,
                "sum_other_doc_count" : 264137,
                "buckets" : [
                  {
                    "key" : "love",
                    "doc_count" : 12542
                  },

```

Is there an easy and performant way to exclude the key of the parent?

---

<div class="post-metadata">

**Author:** ![Peter\_Steenbergen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter_steenbergen/32/22888_2.png) [@Peter\_Steenbergen](https://discuss.elastic.co/u/Peter_Steenbergen)\
**Post date:** [June 26, 2020, 7:39am UTC](https://discuss.elastic.co/t/terms-aggregations-exclude-the-key-of-parent/236977/2 "2020-06-26T07:39:47Z")

</div>

@abdon Do you have any ideas?

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [June 26, 2020, 8:47am UTC](https://discuss.elastic.co/t/terms-aggregations-exclude-the-key-of-parent/236977/3 "2020-06-26T08:47:24Z")

</div>

No, I don't know of an obvious way to let Elasticsearch do it. I'd think the easiest way to do this would be client-side?

---

<div class="post-metadata">

**Author:** ![Peter\_Steenbergen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter_steenbergen/32/22888_2.png) [@Peter\_Steenbergen](https://discuss.elastic.co/u/Peter_Steenbergen)\
**Post date:** [June 26, 2020, 1:23pm UTC](https://discuss.elastic.co/t/terms-aggregations-exclude-the-key-of-parent/236977/4 "2020-06-26T13:23:26Z")

</div>

Oke no sweat, I will give back one more and exclude the same key. But I thaught this could maybe possible within the core.

Happy weekend!

---

<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:** [July 24, 2020, 1:23pm UTC](https://discuss.elastic.co/t/terms-aggregations-exclude-the-key-of-parent/236977/5 "2020-07-24T13:23:34Z")

</div>

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