# BooleanQuery$TooManyClauses with synonym filter

**URL:** <https://discuss.elastic.co/t/booleanquery-toomanyclauses-with-synonym-filter/203636>\
**Category:** Elasticsearch\
**Created:** [October 15, 2019, 11:40am UTC](https://discuss.elastic.co/t/booleanquery-toomanyclauses-with-synonym-filter/203636 "2019-10-15T11:40:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomoko](https://avatars.discourse-cdn.com/v4/letter/t/a88e57/32.png) [@tomoko](https://discuss.elastic.co/u/tomoko)\
**Post date:** [October 15, 2019, 11:40am UTC](https://discuss.elastic.co/t/booleanquery-toomanyclauses-with-synonym-filter/203636/1 "2019-10-15T11:40:15Z")

</div>

How can I avoid TooManyCaluses failure when I use kuromoji tokenizer with the synonym filter with specifying synonym dictionary which contains about 500K words? How can I calculate to find an appropriate value as the max clause count? Or is there any other way not to cause this failure other than increasing max\_clause\_count value with using this synonym dictionary?

**Situation:** Simple Query String fails with TooManyClauses for a word. I can avoid this failure for a word with configuring max\_clause\_count to 153600, but it occurs again for another word, which seems to need more.

**Additional information:** I'm using kuromoji tokenizer with synonym filter with synonym dictionary which contains about 500K words. It does not fail without synonym filter even when I query the same word. It does not fail with synonym filter with another small synonym dictionary, either.

**Environment:**  
Elasticsearch v5.6.8  
/etc/elasticsearch/elasticsearch.yml  
indices.query.bool.max\_clause\_count: 153600

**Query body:**  
{  
"query": {  
"simple\_query\_string": {  
"query": "atext",  
"fields": ["field1"],  
}  
}  
}

**Error log:** /var/log/elasticsearch/elasticsearch.log  
org.elasticsearch.index.query.QueryShardException: failed to create query: {  
"simple\_query\_string" : {  
"query" : "atext",  
"fields" : [  
"field1^1.0"  
],  
"flags" : -1,  
"default\_operator" : "or",  
"lenient" : false,  
"analyze\_wildcard" : false,  
"boost" : 1.0  
}  
}  
Caused by: org.apache.lucene.search.BooleanQuery$TooManyClauses: maxClauseCount is set to 153600

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [October 16, 2019, 7:53am UTC](https://discuss.elastic.co/t/booleanquery-toomanyclauses-with-synonym-filter/203636/2 "2019-10-16T07:53:19Z")

</div>

Do you know the word the query fails for? Is it just one token? Can you check what it analyzes to if you use the "\_analyze" endpoint for it, using the same analyzer you have configured for that target field?  
For further ideas and for others to chime in on your question it would also be helpful to see the analysis chain and the mapping of your index. It would also be interesting to know if you observe the same behaviour with a more recent version of ES than 5.6.

---

<div class="post-metadata">

**Author:** ![tomoko](https://avatars.discourse-cdn.com/v4/letter/t/a88e57/32.png) [@tomoko](https://discuss.elastic.co/u/tomoko)\
**Post date:** [October 17, 2019, 5:37am UTC](https://discuss.elastic.co/t/booleanquery-toomanyclauses-with-synonym-filter/203636/3 "2019-10-17T05:37:56Z")

</div>

Hi, cbuescher. Thank you for your support. Here are answers.

Elasticsearch analyzes the word into 5097 tokens with using the same analyzer configured for that target field. The word is Japanese.

data = es.indices.analyze(  
index=esIndex,  
body={  
"analyzer": my\_analyzer,  
"text": "atext"}  
)  
numoftoken = len(data.get("tokens"))

When max\_clause\_count is 102400,  
word.A : 5097 tokens -\> TooManyClause error  
word.B : 716 tokens -\> TooManyClause error  
word.C : 4691 tokens -\> OK

When max\_clause\_count is 153600,  
word.A : 5097 tokens -\> TooManyClause error  
word.B : 716 tokens -\> OK  
word.C : 4691 tokens -\> OK

Here is the mapping of the index.  
setting = {  
"settings": {  
"index" : { "number\_of\_shards": 1 },  
"analysis": {  
"analyzer": {  
"my\_analyzer": {  
"type": "custom", "tokenizer": "search-kuromoji", "filter" : ["synonym", "greek\_lowercase", "katakana\_readingform"]}  
},  
"tokenizer": {  
"search-kuromoji": {"type": "kuromoji\_tokenizer", "mode": "search"}  
},  
"filter": {  
"synonym": {"type": "synonym", "synonyms\_path": SYNONYMS\_PATH},  
"greek\_lowercase": {"type": "lowercase", "language": "greek"},  
"katakana\_readingform": {"type": "kuromoji\_readingform", "use\_romaji" : False}  
}  
}  
}  
}  
mappings = {  
'symptom': {  
'properties': {  
'field1': {'type': 'text', 'index': 'true', 'analyzer': 'my\_analyzer'},  
'code': {'type': 'text'}  
}  
}  
}

es.indices.create(index=an\_index, body=setting, request\_timeout=30)  
es.indices.put\_mapping(index=index, doc\_type=a\_doctype, body=mappings)

---

<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:** [November 14, 2019, 5:38am UTC](https://discuss.elastic.co/t/booleanquery-toomanyclauses-with-synonym-filter/203636/4 "2019-11-14T05:38:11Z")

</div>

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