Elasticsearch Function Scoring based on max score within array / nested Elasticsearch Function Scoring based on max score within array / nested elasticsearch elasticsearch

Elasticsearch Function Scoring based on max score within array / nested


One way to achieve this using groovy is as below i.e you can use the max method of list on values.

Example :

{   "query": {      "function_score": {         "functions": [            {               "script_score": {                  "script": "max_score=doc[\"foo.bar\"].values.max();if(max_score >= input) {return (max_score - input);} else { return (max_score - input) *2;}",                  "lang": "groovy",                  "params": {                     "input": 10                  }               }            }         ],         "score_mode": "max",         "boost_mode": "replace"      }   }}