I have this kind of Groovy script:
def multiplier = doc['data'].value
if (multiplier <= 0) {
multiplier = 1
}
multiplier * _score
I use it as a script_score
, and my score is always 0. It seems like _score
is always 0. With a mvel script, it works.
mvel script was:
_score * doc['data'].value
Query is (only lang
changes for the mvel version):
"function_score": {
query: {
"bool": {
"should": [
// many matches...
],
"minimum_should_match": 1,
},
},
"script_score": {
"lang": "groovy",
"file": "my_script",
},
"boost": 2.5,
"score_mode": "max",
}
Am I doing something wrong? I tested this on Elasticsearch 1.5.2.
I don't have a good explanation for this, but this query works for me in Groovy (had to enable logging in the script to see what
_score
is containing):