# Hitting 'too\_many\_clauses' exception when used in aggregation filter context

**URL:** <https://discuss.elastic.co/t/hitting-too-many-clauses-exception-when-used-in-aggregation-filter-context/247010>\
**Category:** Elasticsearch\
**Created:** [August 31, 2020, 8:13pm UTC](https://discuss.elastic.co/t/hitting-too-many-clauses-exception-when-used-in-aggregation-filter-context/247010 "2020-08-31T20:13:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karthik\_Arun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karthik_arun/32/74852_2.png) [@Karthik\_Arun](https://discuss.elastic.co/u/Karthik_Arun)\
**Post date:** [August 31, 2020, 8:13pm UTC](https://discuss.elastic.co/t/hitting-too-many-clauses-exception-when-used-in-aggregation-filter-context/247010/1 "2020-08-31T20:13:44Z")

</div>

I have a terms query returning over 5k clauses and when this is used within the filter context of the query, I never hit this 'too\_many\_clauses exception - you have exceeded 1024 clauses'.

However if I use this terms query within the aggregation, I am hitting 'too\_many\_clauses exception'. Is there a way to get past this?

```auto
aggs:{
"filter": 
      {
        "bool": {
          "must": [
            {
              "terms": {

              -- 
              }
            }
          ]

```

---

<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 28, 2020, 8:13pm UTC](https://discuss.elastic.co/t/hitting-too-many-clauses-exception-when-used-in-aggregation-filter-context/247010/2 "2020-09-28T20:13:53Z")

</div>

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