Why does the ordering of and or with an and filter matter in elasticsearch? -
i have below query elasticsearch 2.3.1:
{ "query": { "bool": { "must": { "query": { "multi_match": { "query": "my search", "type": "cross_fields", "fields": ["field1^6", "field2", "field3^2", "field4"], "operator": "and", "zero_terms_query": "all" } } } }, "filter": { "or": [{ "term": { "pickup": true } }, { "term": { "local_delivery": true } }], "and": [{ "term": { "field5": true } }, { "term": { "field6": "my_value" } }] } } } }
this query returns 11k results. if switch ordering of or , and below:
{ "query": { "bool": { "must": { "query": { "multi_match": { "query": "my search", "type": "cross_fields", "fields": ["field1^6", "field2", "field3^2", "field4"], "operator": "and", "zero_terms_query": "all" } } } }, "filter": { "and": [{ "term": { "field5": true } }, { "term": { "field6": "my_value" } }], "or": [{ "term": { "pickup": true } }, { "term": { "local_delivery": true } }] } } } }
i have 675 results.
shouldn't these queries exact same? in essence want filter query have field5 true , field6 my_value. want either of pickup or local_delivery true, so:
(field5 == true && field6 == "my_value" || (pickup == true || local_delivery == true))
using bool query fixes problem:
"filter": { "bool": { "should": [{ "term": { "pickup": true } }, { "term": { "local_delivery": true } }], "must": [{ "term": { "field5": true } }, { "term": { "field6": "my_value" } }] } }
Comments
Post a Comment