I've been using a lot of match
queries in my project. Now, I have just faced with term
query in Elasticsearch. It seems the term query is more faster in case that keyword of your query is specified.
Now I have a question there..
Should I refactor my codes (it's a lot) and use term instead of match?
How much is the performance of using term better than match?
using term in my query:
main_query["query"]["bool"]["must"].append({"term":{object[..]:object[...]}})
using match query in my query:
main_query["query"]["bool"]["must"].append({"match":{object[..]:object[...]}})
Elastic discourages to use term
queries for text
fields for obvious reasons (analysis!!), but if you know you need to query a keyword
field (not analyzed!!), definitely go for term/terms
queries instead of match
, because the match
query does a lot more things aside from analyzing the input and will eventually end up executing a term
query anyway because it notices that the queried field is a keyword
field.