0
votes

I use the the elastic search's script_score to get the value of a long type field by using the doc['field_name'] syntax`,while the query action throw a exception. the query syntax and the detail of the exception is as below:

     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
Try to look into how to correctly escape the single quotes in the line that says "inline": "doc['score'].value"Daniel Gray
Perhaps something like "inline": "doc[\"score\"].value" will work?Daniel Gray
@DanielGray To change the inline syntax to be "inline": "doc[\"score\"].value" is successful. Thanks a lot.smilepy

1 Answers

0
votes

Escape the value of the inline key of the script element... the back-end parser seems to not handle single-quote characters well.

Change the single quote characters (') to an escaped normal/double quote (", prepended by \) or, change the line:

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

to

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