I use easlticsearch 6.
Query with filter:
"query":{
"bool":{
"must":[{
"bool":{
"minimum_should_match":1,
"should":[
{"wildcard":{"header":"*hello*"}},
{"wildcard":{"body":"*hello*"}}
]
}
}],
"filter":[{
"bool":{
"must":[
{"terms":{"puid":["user1"]}},
{"terms":{"fid":["user1-1519812713"]}}
]
}
}]
}
}
Query without filter:
"query":{
"bool":{
"must":[
{"term":{"puid":"user1"}},
{"terms":{"fid":["user1-1519812713"]}},
"bool":{
"minimum_should_match":1,
"should":[
{"wildcard":{"header":"*hello*"}},
{"wildcard":{"body":"*hello*"}}
]
}}
]
}
}
When I measure the performance of both queries with curl: curl -w'\ntime_total:%{time_total}\n' -H 'Content-Type: application/json' -XGET -d '{}' :9200/store/msg/_search?routing=user1
The time total I got for the query without filter: 1.134, 1.237, 1.107 with filter: 1.322, 1.454, 1.316
I expect that the query with filter provides better performance since it doesn't need to calculate the score, and it can be cached. Elastic also recommends filter in bool query.