Reputation: 1245
I need to get all documents that contain at least one item from a list of more than 1024.
My query is basically a bool query with a should and minimum_should_match: 1.
Elasticsearch maxClauseCount is set to 1024 by default. I have tried to set it to 4096 and the configuration looks to be ok:
I request http://myserver:9200/my_index/_settings and get:
...
"query": {
"bool": {
"max_clause_count": "4096"
}
}
...,
But if I try still get TooManyClauses[maxClauseCount is set to 1024]
in my logs.
1st Question: Why is this contradictory?
I have read that for some cases it is better to use a filter instead of a large bool:
In general I'd recommend to rewrite that query to use terms filter instead of boolean query https://discuss.elastic.co/t/too-many-clauses-maxclausecount-is-set-to-1024/61968
2nd Question: How could I use a filter to obtain the same logic as the multiple should bool on my example? What is best bool filter or filtered filter for that case?
Upvotes: 2
Views: 1367
Reputation: 1245
I am not yet sure why Elasticsearch raise the maxClauseCount error, but i have found an alternative way to structure my query.
The (easy) solution is to use terms with the large list of items. If I use it into a must
I get the same error, but with filter
it works perfectly.
Example:
{
"query": {
"bool": {
"filter": [
{"terms": {"my_field": ["item1", "item2", ... "itemN"]}}
]
}
}
}
The only lack for filter
is that:
The clause (query) must appear in matching documents. However unlike must the score of the query will be ignored. https://www.elastic.co/guide/en/elasticsearch/reference/2.3/query-dsl-bool-query.html
Upvotes: 2