# How to create an array runtime field

**URL:** <https://discuss.elastic.co/t/how-to-create-an-array-runtime-field/322791>\
**Category:** Kibana\
**Created:** [January 10, 2023, 6:27am UTC](https://discuss.elastic.co/t/how-to-create-an-array-runtime-field/322791 "2023-01-10T06:27:37Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![cr\_168328](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@cr\_168328](https://discuss.elastic.co/u/cr_168328)\
**Post date:** [January 11, 2023, 6:23am UTC](https://discuss.elastic.co/t/how-to-create-an-array-runtime-field/322791/10 "2023-01-11T06:23:11Z")

</div>

> [@Marco\_Liberati](#):
>
> Based on this answer it seems that deprecated scripted field can provide some help

I have tried using `param._source` as suggested, but still not working.

This is not populating the runtime field:

```auto
PUT employee/_mappings
{
  "runtime": {
    "empRoles": {
      "type": "keyword",
      "script": """if (doc["roles.name.raw"].size()!=0 ) {
        for(item in params._source.roles.name.raw) {
          emit(item) ;
        }
        
         }
         """
    }
  }
}

```

The following one results in error `cannot cast from [java.lang.String[]] to [void]`, as expected:

```auto
PUT employee/_mappings
{
  "runtime": {
    "empRoles": {
      "type": "keyword",
      "script": """String[] empRoles;
        if (doc["roles.name.raw"].size()!=0 ) {
        int i=0;
        for(item in params._source.roles.name.raw) {
          empRoles[i++]=item
        }
        
         }
return empRoles;
         """
    }
  }
}

```

---

_[View the full topic](https://discuss.elastic.co/t/how-to-create-an-array-runtime-field/322791)._
