# maxClauseCount error on Multi Match after Upgrade to 7.10.1

**URL:** <https://discuss.elastic.co/t/maxclausecount-error-on-multi-match-after-upgrade-to-7-10-1/266160>\
**Category:** Elasticsearch\
**Created:** [March 3, 2021, 9:20pm UTC](https://discuss.elastic.co/t/maxclausecount-error-on-multi-match-after-upgrade-to-7-10-1/266160 "2021-03-03T21:20:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dwhite44](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dwhite44/32/12774_2.png) [@dwhite44](https://discuss.elastic.co/u/dwhite44)\
**Post date:** [March 3, 2021, 9:20pm UTC](https://discuss.elastic.co/t/maxclausecount-error-on-multi-match-after-upgrade-to-7-10-1/266160/1 "2021-03-03T21:20:06Z")

</div>

We are in the process of upgrading from Elasticsearch 6.5.4 to 7.10.1. We have some searches that worked fine against 6.5.4 but are getting "failed to create query: maxClauseCount is set to 1024" errors against 7.10.1. Here is an example of the query:

```
"query": {
    "bool": {
        "must": [
            {
                "query_string": {
                    "default_operator": "and",
                    "fields": [
                        "field1^4",
                        "field2^3",
                        "field3^2.5",
                        "field4^2",
                        "field5^1.5",
                        "field6",
                        "field7",
                        "field8",
                        "field9",
                        "field10^1.7",
                        "field11",
                        "field12"
                    ],
                    "query": "long query with synonyms",
                    "tie_breaker": 0.3
                }
            }
        ],
        "should": [
            {
                "multi_match": {
                    "fields": [
                        "field1^4",
                        "field2^3",
                        "field3^2.5",
                        "field4^2",
                        "field5^1.5",
                        "field6",
                        "field7",
                        "field8",
                        "field9"
                    ],
                    "query": "long query with synonyms",
                    "slop": 2,
                    "type": "phrase",
                    "boost": 5.0
                }
            }
        ]
    }
}

```

The factors that seem to determine whether it generates too many clauses seem to be the number of terms, whether those terms have synonym entries, being a phrase query and the slop. The term that I know fails does not fail with a slop of 0 but will fail with any positive value for slop. I have multiple questions. Obviously my main objective is to fix my issue but I also want to understand better what is going on. Clearly, something happened internally in the way that queries are expanded into Lucene boolean clauses and there are more being generated now than before. Looking at the profile on the query, it looks like quite a few clauses are being created for synonyms. The multi\_match with type phrase and positive slop is definitely the problem area. If I remove the query\_string search, it makes no impact on whether I get the error or not. And if I change the multi\_match to a query\_string query, make the query in quotes making it a phrase, and give a positive phrase\_slop, I get the same error. The reason for both the queries is because I want all matches that contain all terms but I want those that match the phrase to be ranked higher. Is there a better way to do that? I definitely get different rankings without both searches being there. I'm kind of surprised that phrase query is apparently creating more clauses. I would have thought it would create less especially with "auto\_generate\_synonyms\_phrase\_query" set to false but I guess that's where the slop comes in.

I would appreciate any guidance on what might be happening and how I can fix it. If I do need to increase the max\_clause\_count setting, I guess there's no way to do it by index or even by query so that I can ensure no other queries on other indexes can accidentally exceed that count?

---

<div class="post-metadata">

**Author:** ![dwhite44](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dwhite44/32/12774_2.png) [@dwhite44](https://discuss.elastic.co/u/dwhite44)\
**Post date:** [March 4, 2021, 9:39pm UTC](https://discuss.elastic.co/t/maxclausecount-error-on-multi-match-after-upgrade-to-7-10-1/266160/2 "2021-03-04T21:39:20Z")

</div>

I was able to fix this by changing the phrase search to use an analyzer that did not include synonyms.

---

<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:** [April 1, 2021, 9:39pm UTC](https://discuss.elastic.co/t/maxclausecount-error-on-multi-match-after-upgrade-to-7-10-1/266160/3 "2021-04-01T21:39:47Z")

</div>

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