Not possible to emit List for keyword runtime field

In Elasticsearch 7.15.0, I am unable to emit a list of strings for a keyword runtime field:

PUT warning

PUT warning/_mapping
{
  "dynamic": false,
  "runtime": {
    "Warning": {
      "type": "keyword",
      "script": {
        "source": "emit(['Warning 1']);"
      }
    }
  }
}

==>

{
  "error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "compile error",
        "script_stack" : [
          "emit(['Warning 1']);",
          "     ^---- HERE"
        ],
        "script" : "emit(['Warning 1']);",
        "lang" : "painless",
        "position" : {
          "offset" : 5,
          "start" : 0,
          "end" : 20
        }
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "Failed to parse mapping [_doc]: compile error",
    "caused_by" : {
      "type" : "script_exception",
      "reason" : "compile error",
      "script_stack" : [
        "emit(['Warning 1']);",
        "     ^---- HERE"
      ],
      "script" : "emit(['Warning 1']);",
      "lang" : "painless",
      "position" : {
        "offset" : 5,
        "start" : 0,
        "end" : 20
      },
      "caused_by" : {
        "type" : "class_cast_exception",
        "reason" : "Cannot cast from [java.util.ArrayList] to [java.lang.String]."
      }
    }
  },
  "status" : 400
}

Is this the expected behavior or am I doing something wrong?

Scripts can call the emit method multiple times to emit multiple values.

I missed this in the documentation.

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