Elasticsearch: _score is always 0 in Groovy script

I have this kind of Groovy script:

def multiplier = doc['data'].value
if (multiplier <= 0) {
  multiplier = 1
}
multiplier * _score

I use it as script_score, and my score is always 0. It _scorealways seems to be 0. It works with the mvel script.

mvel script was:

_score * doc['data'].value

Request (only langchanges for 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.

+4
source share
1 answer

I have no good explanation for this, but this request works for me in Groovy (he needed to enable logging in the script to see what it contains _score):

multiplier * _score.score()
+3
source

All Articles