最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

opensearch - Elasticsearch script_fields – how to access document score? - Stack Overflow

programmeradmin7浏览0评论

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?

Share Improve this question asked yesterday Gey NevskyGey Nevsky 1401 gold badge4 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default -1
GET /_search
{
  "query": { "match_all": {} },
  "script_fields": {
    "my_score": {
      "script": {
        "lang": "painless",
        "source": "return params['_score'] * 2"
      }
    }
  }
}
发布评论

评论列表(0)

  1. 暂无评论