It's hard to give general performance advice. It's always best to test how specific queries perform on your documents, like you have done already. But keep in mind that measuring the performance of a single query executed once may not be representative.
Having said that - let me try to give you some pointers.
In general, if you do not care about a score, using a filter
is better than using a bool query's must
or should
clause. Elasticsearch will not have to calculate a score for filters, so that will be faster. Additionally, some filters can be cached by Elasticsearch, which can have a significant positive impact on your cluster. So, for these two reasons - I would not go with your first query.
With regard to your queries 2 and 3: the category
field is mapped as type short
. Do you really need that field to be a number? Are you running mathematical operations like sum or average aggregations on that field? If not, it may be better to map that field as type keyword
. Then, query 3 is going to be the most performant. As it is, with category
mapped as type short
, query 2 may be more performant, as numeric types are optimized for range
queries.
You can find more general advice in our documentation here: https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-for-search-speed.html