如何定义和使用ElasticSearch的脚本并正确使用它

时间:2018-09-10 15:40:47

标签: elasticsearch

我正在尝试定义以下平凡的脚本,但是在查询时却无法很好地编译

POST _scripts/calculate-score
{
  "script": {
    "lang": "painless",
    "source": "ctx._score"
  }
}


GET mygame/_search
{
  "query": {
    "script": {
      "script": {
        "id": "calculate-score",
        "params": {
          "my_modifier": 2
        }
      }
    }
  }
}

它返回:

{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "compile error",
        "script_stack": [
          "ctx._score",
          "^---- HERE"
        ],
        "script": "ctx._score",
        "lang": "painless"
      }

我不知道实际上是怎么了。我什至尝试用数字替换ctx._score,但没有任何变化。

0 个答案:

没有答案