[Answer]-Search – Calculating relevance based on how close keywords are to the far left?

1👍

When you query elasticsearch you get back the _score field for each document, and if you add the explain=on parameter to the url you get back an explanation regarding the score as well, through which you can understand why a document is on top or not.

Anyway, I guess your first document gets the highest score because it contains the word Jeff twice. The third document is the last one because the text field is longer than the others and it contains only a Jeff match. This is how the Lucene score is computed. You can tweak it, for example disabling the fact that the length of the field influences the score, but you can’t completely change the logic behind it unless you’re willing to writing some Lucene code. You could do it writing your own Lucene Similarity implementation and plug it in elasticsearch with a custom SimilarityProvider. Have a look at this example.

Leave a comment