In the above parameters, the bool keyword can still be used for queries.
Calculation rules of associated scores:
Each sub-query calculates the relevance score of the document independently. Once their scores are calculated, the bool query will combine these scores and return a score representing the entire bool operation.
View test cases:
As can be seen from the above figure, filter is only a filtering condition and does not calculate _score, while should only calculates _score and does not filter.
Filter does not need to calculate related scores, nor does it need to sort by related scores. At the same time, the data of the most commonly used filters are automatically cached. Good performance.
Query operation is just the opposite, it will calculate the correlation score and sort it according to the results, so it can't cache the results and its performance is not good.
Therefore, in some query scenarios that do not need associated scores, try to use FilterContext to optimize query performance.
Constant_score: Original meaning (constant score), which can apply a constant to all matching documents. It is usually used when only one filter needs to be executed and no other queries (such as scoring queries) need to be executed. This $ term query is placed in constant_score and converted into a filter that does not score. This method can be used in bool queries with only filters.
Data preparation:
Its essence is equivalent to:
It's just that there is only the filter operation in bool, so constant_score is used instead of the filter operation to set a constant score for each subquery.
From the above results, we can also see the calculation rule of _score: each sub-query calculates the relevance score of doc independently, and once their scores are calculated, bool query combines these scores and returns a score representing the whole bool operation.
Different from using constant_score, should participates in the score calculation, and the boost we set is only the weight ratio of participating in the score. Not a specific decimal value. This is why the fraction calculated in this way has decimals.
1, "Summer of Love" character introduction: Xia is an independent designer, brave and upright; Xu Zehao is the boss of the space design office, straight