Query String in Lucene syntax vs Term Filter Performance

Is there any performance difference if I write out the query string in Lucene syntax vs using the term filter in dicts?

In my particular use case, I find it easier to type out my logic in a list and join them with ANDs so doing it in query_string is preferred as it is both more readable and easier to write — but if the native term filter is faster, I would’ve used it. All of them are field keyword filters (that a field exactly match a string)

Is the score identical in both cases? 1?

I don’t actually care about the score. I am using them as filters to do aggregations.

I got that. I'm asking if in your tests you are getting the same score or not.

Score are both 0. This is what I get from my test queries:

  "took" : 32,
  "timed_out" : false,
  "_shards" : {
    "total" : 20,
    "successful" : 20,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 64053,
    "max_score" : 0.0,
    "hits" : []
  }
}

First time I run the query it returns after 200 msec but if I run it again it is faster (~20-30) because it s perhaps cached? I am using bool query for both.

Great. So no score is ran which means to me that's it's considered as filters. The good thing is that filters are cached which explains also a faster execution after some runs.

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