I want to add a script_field
to the result of an Elasticsearch query that performs a calculation based on the document’s score. However, I can't find a way to access the score inside the script.
I tried something like this:
GET /_search
{
"query": { "match_all": {} },
"script_fields": {
"my_score": {
"script": {
"lang": "painless",
"source": "return _score * 2"
}
}
}
}
But this raises a "compile error" at the _score
expression.
I also tried using doc['_score'].value
, but it returns "No field found for [_score] in mapping."
Is there a way to access the score inside a script_field
?
I want to add a script_field
to the result of an Elasticsearch query that performs a calculation based on the document’s score. However, I can't find a way to access the score inside the script.
I tried something like this:
GET /_search
{
"query": { "match_all": {} },
"script_fields": {
"my_score": {
"script": {
"lang": "painless",
"source": "return _score * 2"
}
}
}
}
But this raises a "compile error" at the _score
expression.
I also tried using doc['_score'].value
, but it returns "No field found for [_score] in mapping."
Is there a way to access the score inside a script_field
?
1 Answer
Reset to default -1GET /_search
{
"query": { "match_all": {} },
"script_fields": {
"my_score": {
"script": {
"lang": "painless",
"source": "return params['_score'] * 2"
}
}
}
}