Elasticsearch : _score always 0 in Groovy script

587 Views Asked by At

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.

1

There are 1 best solutions below

3
On BEST ANSWER

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):

multiplier * _score.score()