# Add Map to Array with Painless script

**URL:** https://discuss.elastic.co/t/add-map-to-array-with-painless-script/69145
**Category:** Elasticsearch
**Created:** [December 15, 2016, 10:23am UTC](https://discuss.elastic.co/t/add-map-to-array-with-painless-script/69145 "2016-12-15T10:23:13Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![matw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matw/32/13913_2.png) [@matw](https://discuss.elastic.co/u/matw)
#### Post date: [December 15, 2016, 10:23am UTC](https://discuss.elastic.co/t/add-map-to-array-with-painless-script/69145/1 "2016-12-15T10:23:13Z")

</div>

Wanted to convert a script to painless which was quite painful. had the following problem:

this works:

```
POST /logstash-test/test/7/_update
{
    "scripted_upsert":true,
    "script" : {
        "lang": "painless",
        "inline": "ctx._source.messages=[]; ctx._source.messages.add('23')",
        "params" : {
            "event" : {"@timestamp":"11232"}
        }
    }
}

```

this doesn't work

```
POST /logstash-test/test/7/_update
{
    "scripted_upsert":true,
    "script" : {
        "lang": "painless",
        "inline": "ctx._source.messages=[]; ctx._source.messages.add(['test':'123'])",
        "params" : {
            "event" : {"@timestamp":"11232"}
        }
    }
}

```

i get the following error:

```
{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse [messages]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "failed to parse [messages]",
    "caused_by": {
      "type": "illegal_state_exception",
      "reason": "Can't get text on a START_OBJECT at 1:14"
    }
  },
  "status": 400
}

```

how can i make this work (Elasticsearch 5.1)? thx!

---

<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: [January 12, 2017, 10:23am UTC](https://discuss.elastic.co/t/add-map-to-array-with-painless-script/69145/2 "2017-01-12T10:23:29Z")

</div>

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