ES7 Multiply scores from boolean queries


Is it possible in some way to multiply the scores of two boolean queries?

I now BoolQuery.Should can add the scores together, but not multiply.
Another possibility is function scores, but here I can only provide a filter, and not ie a boolQuery, so I can not use the score of the filter (since it is not scoring).
I can use script_score, but then I have to express my boolQuery in a script, and that is tricky.

Any help is appreciated

No there is no way to multiply scores from two queries.
We have not encountered a case where it would make sense to multiply scores.

Hey Mayya, thanks for the answer!

My use case is that I wish to be able to use boolqueries as "building blocks" for my query.

Ie I have a base scoring algorithm, which I always use.

Together with my base scoring, I will make a possibility to multiply different factors to the scoring, depending on some different conditions.

I know I can do this using function score and filters, but then I cant use the scoring of the filter as part of the multiplier as I understands?

Since I cant use the score of the filter, I also have to make a filter for each condition I want to use, which can end up in a lot of filters - which seems to be quite slow.
If I could use the score, I could instead build a boolQuery returning the factor I wish to multiply with.

And if I could multiply score of ie a should in a boolQuery, I wouldnt need any function scores applied at all


@JF2018 Thank you for providing your use case. I guess what I meant is that we have not encountered a case where it makes sense to multiply scores from two textual queries where meaningful scores are produced.

For all other cases, you can use function_score query with filters.

One case where it could be meaningful is if you ie use constant score query in you bool query.
Den depending on which fields are available in the document, you can calculate a factor you wish to multiply the score with.

Instead of having multiple functions, I could use one bool query, building up the factor.

Another use case could be, if you have a custom similarity score on a field, and wish to use this value as a factor - and not the direct value of the field.

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