# Not possible to emit List for keyword runtime field

**URL:** <https://discuss.elastic.co/t/not-possible-to-emit-list-for-keyword-runtime-field/285397>\
**Category:** Elasticsearch\
**Tags:** painless, runtime-fields\
**Created:** [September 28, 2021, 5:25pm UTC](https://discuss.elastic.co/t/not-possible-to-emit-list-for-keyword-runtime-field/285397 "2021-09-28T17:25:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomhe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomhe/32/120065_2.png) [@tomhe](https://discuss.elastic.co/u/tomhe)\
**Post date:** [September 28, 2021, 5:25pm UTC](https://discuss.elastic.co/t/not-possible-to-emit-list-for-keyword-runtime-field/285397/1 "2021-09-28T17:25:52Z")

</div>

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

```auto
PUT warning

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

```

==\>

```auto
{
  "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?

---

<div class="post-metadata">

**Author:** ![tomhe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomhe/32/120065_2.png) [@tomhe](https://discuss.elastic.co/u/tomhe)\
**Post date:** [October 7, 2021, 1:53pm UTC](https://discuss.elastic.co/t/not-possible-to-emit-list-for-keyword-runtime-field/285397/2 "2021-10-07T13:53:37Z")

</div>

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

I missed this in the documentation.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 4, 2021, 1:53pm UTC](https://discuss.elastic.co/t/not-possible-to-emit-list-for-keyword-runtime-field/285397/3 "2021-11-04T13:53:50Z")

</div>

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