# TooManyClauses error in Query String query - trying to rewrite

**URL:** <https://discuss.elastic.co/t/toomanyclauses-error-in-query-string-query-trying-to-rewrite/19837>\
**Category:** Elasticsearch\
**Created:** [September 17, 2014, 10:15am UTC](https://discuss.elastic.co/t/toomanyclauses-error-in-query-string-query-trying-to-rewrite/19837 "2014-09-17T10:15:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Markos\_Fragkakis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markos_fragkakis/32/1275_2.png) [@Markos\_Fragkakis](https://discuss.elastic.co/u/Markos_Fragkakis)\
**Post date:** [September 17, 2014, 10:15am UTC](https://discuss.elastic.co/t/toomanyclauses-error-in-query-string-query-trying-to-rewrite/19837/1 "2014-09-17T10:15:03Z")

</div>

Hello,

My query\_string query gives me a TooManyClauses exception, and I am trying  
to avoid it with the rewrite parameter. This is my original query:

{  
"query" : {  
"query\_string" : {  
"query" : "+substance +ATT\_UUID:\* +filename:\*pdf",  
"default\_field" : "fileTextContent.fileTextContentAnalyzed"  
}  
},  
"fields" : [ "attachmentType", "DOS\_UUID", "ATT\_UUID", "filename",  
"isCSR", "mime", "md5", "filesize" ],  
"highlight" : {  
"fields" : {  
"fileTextContent.fileTextContentAnalyzed" : { }  
}  
}  
}

and it gives me the TooManyClauses error:

{  
"error": "SearchPhaseExecutionException[Failed to execute phase  
[query\_fetch], all shards failed; shardFailures  
{[S8DPjOR9TKmCzMhnQXeo7g][markosindex][0]:  
FetchPhaseExecutionException[[markosindex][0]:  
query[+fileTextContent.fileTextContentAnalyzed:substance +ATT\_UUID:\*  
+filename:\*pdf],from[0],size[10]: Fetch Failed [Failed to highlight field  
[fileTextContent.fileTextContentAnalyzed]]]; nested:  
TooManyClauses[maxClauseCount is set to 1024]; }]",  
"status": 500  
}

This is normal I guess since I am using wildcards, so under the hood this  
is translated to multiple boolean clauses that exceed the default 1024  
limit. I tried to use the rewrite parameter, as instructed in several posts  
(the Query String Query  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html)  
does support rewrite  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-multi-term-rewrite.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-multi-term-rewrite.html)).  
However, the rewrite parameter seems to be ignored, as any of the values  
gives the same error as before. My query is below, what something wrong  
with it?

Thanks!

{  
"query" : {  
"query\_string" : {  
"query" : "+substance +DOS\_UUID:\* +ATT\_UUID:\* +filename:\*pdf",  
"default\_field" : "fileTextContent.fileTextContentAnalyzed",

- 

```
 "rewrite": "constant_score_filter"*

```

}  
},  
"fields" : [ "attachmentType", "DOS\_UUID", "ATT\_UUID", "filename",  
"isCSR", "mime", "md5", "filesize" ],  
"highlight" : {  
"fields" : {  
"fileTextContent.fileTextContentAnalyzed" : { }  
}  
}  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e8720ab9-39f6-4c48-a9b7-e9fd135ef897%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e8720ab9-39f6-4c48-a9b7-e9fd135ef897%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:01am UTC](https://discuss.elastic.co/t/toomanyclauses-error-in-query-string-query-trying-to-rewrite/19837/2 "2017-07-06T01:01:39Z")

</div>

Closed on July 6, 2017, 1:01am UTC


