EJay
EJay

Reputation: 338

Elastic Search: score as percentage

Is it possible to make a query for Elastic Search that returns a score as a percentage of the maximum score? Until now it returns a value like "_score": 0.00786336, and also a maximum score like max_score": 0.13435546, so I could try to convert my result but I want the result to be already in percentages, so I could use a minimum score, for example of 40 percent.

In short: Is there a way to get the _score in percentages of the max score, or is there another way of setting a minimum score? (seems to be hard because the max_score seems random)

Upvotes: 10

Views: 12128

Answers (2)

Moghira
Moghira

Reputation: 317

One way to do it can be to store the query hashes and the min_score (calculated as a percentage of max score). For example if the max_score is 1.1 the min_score can be 0.44 for that query which can help cut off irrelevant results.

Upvotes: 0

sjagr
sjagr

Reputation: 16502

max_score is not random, it's simply the max of all the scores of the result set from your query.

The max_score value is the highest _score of any document that matches our query.

For example, if your _score values are: [0.00786336, 0.0123, 0.0813523, 0.13435546], then your max_score is 0.13435546.

There is also no limit to how high the _score may be based on the relevance of your matches (i.e. it can be in excess of 1)

If you're trying to represent a "percentage match" using a ratio of _score from a hit to a max_score, you're going to get unreliable results, especially if you have a lot of low-score hits with little to no relevance, yet the max_score is close to those low scores.

If you're trying to filter out by a minimum score, you should use min_score

Also see "What is Relevance?"

Upvotes: 3

Related Questions