# "match\_phrase\_prefix" TooManyClauses\[maxClauseCount is set to 1024\]

**URL:** <https://discuss.elastic.co/t/match-phrase-prefix-toomanyclauses-maxclausecount-is-set-to-1024/95841>\
**Category:** Elasticsearch\
**Created:** [August 4, 2017, 8:59am UTC](https://discuss.elastic.co/t/match-phrase-prefix-toomanyclauses-maxclausecount-is-set-to-1024/95841 "2017-08-04T08:59:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![felayman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felayman/32/20791_2.png) [@felayman](https://discuss.elastic.co/u/felayman)\
**Post date:** [August 4, 2017, 8:59am UTC](https://discuss.elastic.co/t/match-phrase-prefix-toomanyclauses-maxclausecount-is-set-to-1024/95841/1 "2017-08-04T08:59:18Z")

</div>

when i use "match\_phrase\_prefix" query in my project.

the query is :

```auto
{
  "query": {
    "match_phrase_prefix": {
      "nickName": "a"
    }
  }
}

```

but it throws the exception as follow:

```auto
org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to execute phase [dfs], all shards failed; shardFailures {[J4HFhidITlKtvOlSf2B36A][user][0]: DfsPhaseExecutionException[[user][0]: query[filtered(nickName:"a*"~1)->cache(_type:user)],from[0],size[10]: Dfs Failed [Exception during dfs phase]]; nested: TooManyClauses[maxClauseCount is set to 1024]; }{[J4HFhidITlKtvOlSf2B36A][user][1]: DfsPhaseExecutionException[[user][1]: query[filtered(nickName:"a*"~1)->cache(_type:user)],from[0],size[10]: Dfs Failed [Exception during dfs phase]]; nested: TooManyClauses[maxClauseCount is set to 1024]; }{[porfJBUXRWeSygtrF_rjRg][user][2]: RemoteTransportException[[mq-03][inet[/10.163.6.246:9300]][indices:data/read/search[phase/dfs]]]; nested: DfsPhaseExecutionException[[user][2]: query[filtered(nickName:"a*"~1)->cache(_type:user)],from[0],size[10]: Dfs Failed [Exception during dfs phase]]; nested: TooManyClauses[maxClauseCount is set to 1024]; }{[-kFmY4FhSDe0s1g-j0cn4w][user][3]: RemoteTransportException[[mq-01][inet[/10.162.207.86:9300]][indices:data/read/search[phase/dfs]]]; nested: DfsPhaseExecutionException[[user][3]: query[filtered(nickName:"a*"~1)->cache(_type:user)],from[0],size[10]: Dfs Failed [Exception during dfs phase]]; nested: TooManyClauses[maxClauseCount is set to 1024]; }{[J4HFhidITlKtvOlSf2B36A][user][4]: DfsPhaseExecutionException[[user][4]: query[filtered(nickName:"a*"~1)->cache(_type:user)],from[0],size[10]: Dfs Failed [Exception during dfs phase]]; nested: TooManyClauses[maxClauseCount is set to 1024]; }{[klXNljLDRMKty9yIdOZp6A][user][5]: RemoteTransportException[[design-mq-04][inet[/10.173.34.187:9300]][indices:data/read/search[phase/dfs]]]; nested: DfsPhaseExecutionException[[user][5]: query[filtered(nickName:"a*"~1)->cache(_type:user)],from[0],size[10]: Dfs Failed [Exception during dfs phase]]; nested: TooManyClauses[maxClauseCount is set to 1024]; }{[fu_kgQlKQq2iemZ3v-TKkg][user][6]: RemoteTransportException[[design-mq-03][inet[/10.172.135.214:9300]][indices:data/read/search[phase/dfs]]]; nested: DfsPhaseExecutionException[[user][6]: query[filtered(nickName:"a*"~1)->cache(_type:user)],from[0],size[10]: Dfs Failed [Exception during dfs phase]]; nested: TooManyClauses[maxClauseCount is set to 1024]; }{[T3C8QuLGSZushd71dOHGeg][user][7]: RemoteTransportException[[mq-04][inet[/10.172.187.174:9300]][indices:data/read/search[phase/dfs]]]; nested: DfsPhaseExecutionException[[user][7]: query[filtered(nickName:"a*"~1)->cache(_type:user)],from[0],size[10]: Dfs Failed [Exception during dfs phase]]; nested: TooManyClauses[maxClauseCount is set to 1024]; }{[T3C8QuLGSZushd71dOHGeg][user][8]: RemoteTransportException[[mq-04][inet[/10.172.187.174:9300]][indices:data/read/search[phase/dfs]]]; nested: DfsPhaseExecutionException[[user][8]: query[filtered(nickName:"a*"~1)->cache(_type:user)],from[0],size[10]: Dfs Failed [Exception during dfs phase]]; nested: TooManyClauses[maxClauseCount is set to 1024]; }{[klXNljLDRMKty9yIdOZp6A][user][9]: RemoteTransportException[[design-mq-04][inet[/10.173.34.187:9300]][indices:data/read/search[phase/dfs]]]; nested: DfsPhaseExecutionException[[user][9]: query[filtered(nickName:"a*"~1)->cache(_type:user)],from[0],size[10]: Dfs Failed [Exception during dfs phase]]; nested: TooManyClauses[maxClauseCount is set to 1024]; }{[porfJBUXRWeSygtrF_rjRg][user][10]: RemoteTransportException[[mq-03][inet[/10.163.6.246:9300]][indices:data/read/search[phase/dfs]]]; nested: DfsPhaseExecutionException[[user][10]: query[filtered(nickName:"a*"~1)->cache(_type:user)],from[0],size[10]: Dfs Failed [Exception during dfs phase]]; nested: TooManyClauses[maxClauseCount is set to 1024]; }{[klXNljLDRMKty9yIdOZp6A][user][11]: RemoteTransportException[[design-mq-04][inet[/10.173.34.187:9300]][indices:data/read/search[phase/dfs]]]; nested: DfsPhaseExecutionException[[user][11]: query[filtered(nickName:"a*"~1)->cache(_type:user)],from[0],size[10]: Dfs Failed [Exception during dfs phase]]; nested: TooManyClauses[maxClauseCount is set to 1024]; }

```

how can i solve it ?

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [August 4, 2017, 10:40am UTC](https://discuss.elastic.co/t/match-phrase-prefix-toomanyclauses-maxclausecount-is-set-to-1024/95841/2 "2017-08-04T10:40:22Z")

</div>

Hi @felayman,

it looks the query is rewritten internally into a large number of boolean queries. While you _could_ increase the limit of 1024 boolean clauses I think this is the wrong route here.

I think there are a number of things to consider here:

1. You're searching for user names. You should not analyze them but rather store them as is (i.e. map them as `keyword` instead of `text` (ES 5.0 and later)). So I think you should be using a [prefix query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html) to begin with.
2. Both the prefix query and the phrase prefix query are very resource intensive. If you want to use this for auto-complete or suggestion there are [alternatives](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html) (see also the [partial matching chapter](https://www.elastic.co/guide/en/elasticsearch/guide/2.x/partial-matching.html) in the Definitive Guide for more context).

If I'm wrong and you really need to use a phrase prefix query, you should limit the number of expansions with the `max_expansions` parameter (see [docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase-prefix.html)) and/or expect the user to enter at least 2 or 3 characters and only then start to hit Elasticsearch.

Daniel

---

<div class="post-metadata">

**Author:** ![felayman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felayman/32/20791_2.png) [@felayman](https://discuss.elastic.co/u/felayman)\
**Post date:** [August 5, 2017, 1:24pm UTC](https://discuss.elastic.co/t/match-phrase-prefix-toomanyclauses-maxclausecount-is-set-to-1024/95841/3 "2017-08-05T13:24:57Z")

</div>

> [@danielmitterdorfer](#):
>
> parameter

@danielmitterdorfer

First at all , so thanks for your reply.

i try to use the max\_expansions([see doc](https://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl-match-query-phrase-prefix.html)) parameter to control to how many suffixes the last term will be expanded. but it doesn't work as expected.

and now i use the prefix query instead of match\_phrase\_prefix query .

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [August 7, 2017, 5:52am UTC](https://discuss.elastic.co/t/match-phrase-prefix-toomanyclauses-maxclausecount-is-set-to-1024/95841/4 "2017-08-07T05:52:38Z")

</div>

> [@felayman](#):
>
> i try to use the max\_expansions(see doc) parameter to control to how many suffixes the last term will be expanded. but it doesn’t work as expected.

To which value(s) did you set `max_expansions` (IIRC the default value is 50)? Can you explain in which way it does not work as expected?

> [@felayman](#):
>
> and now i use the prefix query instead of match\_phrase\_prefix query .

Does this mean that:

1. You have changed your mapping of the field `nickName`
2. You changed your use of `match_phrase_prefix` query to `prefix` query
3. It is working now?

Daniel

---

<div class="post-metadata">

**Author:** ![felayman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felayman/32/20791_2.png) [@felayman](https://discuss.elastic.co/u/felayman)\
**Post date:** [August 11, 2017, 6:56am UTC](https://discuss.elastic.co/t/match-phrase-prefix-toomanyclauses-maxclausecount-is-set-to-1024/95841/5 "2017-08-11T06:56:33Z")

</div>

1.i don't change my mapping.  
2.yes,i change my use of match\_phrase\_prefix query to prefix query  
3.now it works well.

Thanks all ,Daniel.

---

<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 8, 2017, 6:56am UTC](https://discuss.elastic.co/t/match-phrase-prefix-toomanyclauses-maxclausecount-is-set-to-1024/95841/6 "2017-09-08T06:56:33Z")

</div>

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