# Create array in logstash -\> elastic

**URL:** https://discuss.elastic.co/t/create-array-in-logstash-elastic/100512
**Category:** Logstash
**Created:** [September 14, 2017, 10:24am UTC](https://discuss.elastic.co/t/create-array-in-logstash-elastic/100512 "2017-09-14T10:24:39Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Frances\_Buontempo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frances_buontempo/32/16050_2.png) [@Frances\_Buontempo](https://discuss.elastic.co/u/Frances_Buontempo)
#### Post date: [September 14, 2017, 10:24am UTC](https://discuss.elastic.co/t/create-array-in-logstash-elastic/100512/1 "2017-09-14T10:24:39Z")

</div>

I want to update documents, and add some of the fields to an array, e.g. with documents from json like

{ "name": "bill, "hobbies": "a" , "id": 1}

if I run logstash on more data like

{ "name": "ted, "hobbies": "a" , "id": 2}  
{ "name": "bill, "hobbies": "c" , "id": 1}

I'd like to end up with ted having ["a"] as hobbies, and bill with ["a", "c"].

Looking at [Creating/updating array of objects in elasticsearch logstash output](https://discuss.elastic.co/t/creating-updating-array-of-objects-in-elasticsearch-logstash-output/59139) and [Add new values in the nested field - Logstash to Elasticsearch](https://discuss.elastic.co/t/add-new-values-in-the-nested-field-logstash-to-elasticsearch/62253) I've tried adding a script to the output plugin for elasticsearch

```
    script => '
      if (ctx._source.hobbies != null) {
          ctx._source.hobbies.add(params.event.get("hobbies"))
      } else {
          ctx._source.hobbies = [params.event.get("hobbies")]
      }'

```

This fails on the update because the field is a string;

"reason"=\>"Unable to find dynamic method [add] with [1] arguments for class [java.lang.String]."}

How do I persuade it to be an array?  
Is this possible? Is there another option?

Cheers.

---

<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: [October 12, 2017, 10:24am UTC](https://discuss.elastic.co/t/create-array-in-logstash-elastic/100512/2 "2017-10-12T10:24:39Z")

</div>

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