0
votes

When it comes to the "performance difference", I read nothing reliable till now.

Based on its official docs, as to filter used in the bool query

The clause (query) must appear in matching documents. However unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching.

As for constant score query

Filter queries do not calculate relevance scores. To speed up performance, Elasticsearch automatically caches frequently used filter queries.


Just a guess

Constant query will not calculate (TF-IDF or more advanced algs), while the bool query will do the calculation but return 0 (ignoring it); so the constant query is more performant.

Besides when it comes to a specified score, you have to use constant score query instead of bool query which only will return 0.

QAs I just read: Elasticsearch : constant_score query vs bool.filter query

1

1 Answers

0
votes

NO, there is no performance difference since they are the same.

Based on again its offical doc discussing about filter context:

In a filter context, a query clause answers the question “Does this document match this query clause?” The answer is a simple Yes or No — no scores are calculated.

And

Filter context is in effect whenever a query clause is passed to a filter parameter, such as the filter or must_not parameters in the bool query, the filter parameter in the constant_score query, or the filter aggregation.