Compile Error Supplying Param to Script

painless

#1

I'm using ES 6.2.4 and online documentation for this version says one should use parameters to optimize scripting. I'm getting a compile error when trying to do so...

GET group/_search
{
  "min_score": 1,
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "must": [
            {
              "terms": {
                "itemId": [
                  "176947"
                ]
              }
            },
            {
              "match": {
                "name": {
                  "query": "soft drinks",
                  "operator": "and",
                  "fuzziness": "AUTO",
                  "prefix_length": 2
                }
              }
            }
          ]
        }
      },
      "script_score": {
        "script": {
          "params": {
            "terms": 2
          },
          "source": "terms / (float)doc['name.length'].value"
        }
      }
    }
  }
}

Result:

{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "compile error",
        "script_stack": [
          "terms / (float)doc['name. ...",
          "^---- HERE"
        ],
        "script": "terms / (float)doc['name.length'].value",
        "lang": "painless"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "group_20190318_150630",
        "node": "L0vkzTvaRTWOBHtU0PYBdQ",
        "reason": {
          "type": "query_shard_exception",
          "reason": "script_score: the script could not be loaded",
          "index_uuid": "1Gh7dOv3QXOo_8Ta8wm1_w",
          "index": "group_20190318_150630",
          "caused_by": {
            "type": "script_exception",
            "reason": "compile error",
            "script_stack": [
              "terms / (float)doc['name. ...",
              "^---- HERE"
            ],
            "script": "terms / (float)doc['name.length'].value",
            "lang": "painless",
            "caused_by": {
              "type": "illegal_argument_exception",
              "reason": "Variable [terms] is not defined."
            }
          }
        }
      }
    ],
    "caused_by": {
      "type": "script_exception",
      "reason": "compile error",
      "script_stack": [
        "terms / (float)doc['name. ...",
        "^---- HERE"
      ],
      "script": "terms / (float)doc['name.length'].value",
      "lang": "painless",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "Variable [terms] is not defined."
      }
    }
  },
  "status": 400
}

#2

Sigh... The problem is that the online documentation is faulty. https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-using.html#_script_parameters

The example shows:

"source": "doc['my_field'] * multiplier"

And should be:

"source": "doc['my_field'] * params.multiplier"


(system) closed #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.