0
votes

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.

1
Try doing it like this: "filter": [ {"terms":{"puid":["user1"]}}, {"terms":{"fid":["user1-1519812713"]}} ]Alkis Kalogeris
thank you. I gave it a try. The time cost is about the same: 1.339 1.462 1.327Happy
I've added an answer below. Check the profile api for more. For simple queries in your localhost with very few results and very few data, then you can't expect these results to be show you the real picture, for end to end benchmarks, but you can check the internals (profile api) and see what happens there. Even the deserialisation of your request would heavily impact the resultsAlkis Kalogeris

1 Answers

0
votes

First of all you are doing a different query on the second one. In the first you used for terms, in the second you used one term and one terms. Although this should not be something of significance you use the exact same query for your benchmark.

Moreover your filter query is using an inner bool query that I believe is causing the problem. Try changing it into this

"filter": [
  {"terms":{"puid":["user1"]}},
  {"terms":{"fid":["user1-1519812713"]}}
]

Moreover you can check the Profile API for more details about your query