# How to exclude keys by multi-terms/composite aggregations

**URL:** <https://discuss.elastic.co/t/how-to-exclude-keys-by-multi-terms-composite-aggregations/319881>\
**Category:** Elasticsearch\
**Created:** [November 27, 2022, 1:29pm UTC](https://discuss.elastic.co/t/how-to-exclude-keys-by-multi-terms-composite-aggregations/319881 "2022-11-27T13:29:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thijsvdp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thijsvdp/32/146696_2.png) [@Thijsvdp](https://discuss.elastic.co/u/Thijsvdp)\
**Post date:** [November 27, 2022, 1:29pm UTC](https://discuss.elastic.co/t/how-to-exclude-keys-by-multi-terms-composite-aggregations/319881/1 "2022-11-27T13:29:32Z")

</div>

Hi, I am writing an composite aggregation in Elasticsearch like the following:

```auto
POST family_predicted_data/_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "terms": {
            "query_id": [
              1
            ]
          }
        }
      ]
    }
  },
  "aggs": {
    "num_families": {
      "value_count": {
        "field": "family_id"
      }
    },
    "members": {
      "nested": {
        "path": "members"
      },
      "aggs": {
        "continent_assignee": {
          "composite": {
            "sources": [
              {
                "continent": {
                  "terms": {
                    "field": "members.country.keyword",
                    "exclude": ".*"
                  }
                }
              },
              {
                "assignee": {
                  "terms": {
                    "field": "members.assignee.keyword"
                  }
                }
              }
            ]
          },
          "aggs": {
            "num_families": {
              "reverse_nested": {}
            },
            "sort": {
              "bucket_sort": {
                "sort": [
                  {
                    "num_families>_count": {
                      "order": "desc"
                    }
                  }
                ],
                "size": 5
              }
            }
          }
        }
      }
    }
  },
  "track_total_hits": true,
  "size": 0
}

```

Normally terms aggregations have a exclude parameter to exclude keys. In my case I have some keys that are empty strings because of some dirty data. Running this query, I get the following error message:

```auto
{
  "error" : {
    "root_cause" : [
      {
        "type" : "x_content_parse_exception",
        "reason" : "[33:21] [terms] unknown field [exclude]"
      }
    ],
    "type" : "x_content_parse_exception",
    "reason" : "[33:32] [composite] failed to parse field [sources]",
    "caused_by" : {
      "type" : "x_content_parse_exception",
      "reason" : "[33:21] [terms] unknown field [exclude]"
    }
  },
  "status" : 400
}

```

It seems like there is no exclude option for composite aggregations? Is there any other way to exclude such cases where one of the fields have empty strings?

Thanks in advance!

---

<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 25, 2022, 1:30pm UTC](https://discuss.elastic.co/t/how-to-exclude-keys-by-multi-terms-composite-aggregations/319881/2 "2022-12-25T13:30:17Z")

</div>

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