Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use maximum score of a field in script score - ElasticSearch

I'm using ElasticSearch 2.4.0 . Using the script_score, I'm calculating custom score like

{"script":"return ( ((doc.field_a.value)* 0.5) + (_score * 0.5) );"}

I want something like (some normalisation effect on the field_a value):

max_score = doc.field_a.values.max(); 
return ( ((doc.field_a.value)* 0.5)/max_score + (_score * 0.5) );

Any help appreciated.

like image 537
M.Prabha karan Avatar asked Feb 20 '17 14:02

M.Prabha karan


People also ask

How do you get a max score on Elasticsearch?

The basic mechanics are as follows: ElasticSearch Score is normalized between 0..1 ( score/max(score) ), we add our ranking score ( also normalized between 0..1 ) and divide by 2.

How does Elasticsearch calculate score?

Before scoring documents, Elasticsearch first reduces the set of candidate documents by applying a boolean test that only includes documents that match the query. A score is then calculated for each document in this set, and this score determines how the documents are ordered.

What is _score in Elasticsearch?

The _score in Elasticsearch is a way of determining how relevant a match is to the query. The default scoring function used by Elasticsearch is actually the default built in to Lucene which is what Elasticsearch runs under the hood.

How do I change Elasticsearch score?

You can achieve it simply by removing the boost_mode parameter, the default boost_mode is to multiply the _score with whatever value comes out of the field_value_factor function.


1 Answers

Please check on the values api you are calling. I think its returning only a single value

like image 91
Pragadeesh R Avatar answered Sep 29 '22 09:09

Pragadeesh R