使用弹性搜索的script_score通过使用doc ['field_name']语法获取long类型字段的值失败

时间:2017-04-27 11:53:11

标签: elasticsearch

我使用弹性搜索的script_score通过使用doc ['field_name']语法来获取long类型字段的值,而查询操作则抛出异常。 查询语法和异常的详细信息如下:

     curl -XPOST http://211.159.155.44:9200/iktest/item/_search?pretty  -d'
{
  "query": {
    "function_score": {
      "query": {
        "match": {
          "content": "likaifu"
        }
      },
      "functions": [
        {
          "gauss": {
            "date": {
              "offset": "0d",
              "scale":  "5d"
            }
          }
        },
        {
          "script_score": {
            "script": {
              "lang":   "expression",
              "inline": "doc['score'].value"
            }
          }
        }
      ],
      "score_mode": "multiply",
      "boost_mode": "replace"
    }
  }
}
'
"caused_by" : {
      "type" : "query_shard_exception",
      "reason" : "script_score: the script could not be loaded",
      "index_uuid" : "jVYGC8-jTpCCyZJi-VJtmA",
      "index" : "iktest",
      "caused_by" : {
        "type" : "script_exception",
        "reason" : "compile error",
        "caused_by" : {
          "type" : "parse_exception",
          "reason" : "unexpected character '[' on line (1) position (3)",
          "caused_by" : {
            "type" : "lexer_no_viable_alt_exception",
            "reason" : null
          }
        },
        "script_stack" : [
          "doc[score].value",
          "   ^---- HERE"
        ],
        "script" : "doc[score].value",
        "lang" : "expression"
      }
    }

1 个答案:

答案 0 :(得分:0)

转义inline元素的script键的值...后端解析器似乎无法很好地处理单引号字符。

将单引号字符(')更改为转义的普通/双引号(",前缀为\)或更改行:

"inline": "doc['score'].value"

"inline": "doc[\"score\"].value"