# Best way to update and insert array

**URL:** https://discuss.elastic.co/t/best-way-to-update-and-insert-array/233109
**Category:** Elasticsearch
**Created:** [May 18, 2020, 1:02pm UTC](https://discuss.elastic.co/t/best-way-to-update-and-insert-array/233109 "2020-05-18T13:02:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![walter.franssen](https://avatars.discourse-cdn.com/v4/letter/w/50afbb/32.png) [@walter.franssen](https://discuss.elastic.co/u/walter.franssen)
#### Post date: [May 18, 2020, 1:02pm UTC](https://discuss.elastic.co/t/best-way-to-update-and-insert-array/233109/1 "2020-05-18T13:02:07Z")

</div>

Hello,

I wonder wat is the best way to update a document. I want to add a value to an array and also set some meta data in one request.

I have first an update statement like this:  
test/\_update/AaCnJ3IBeJO1gLa1SX7H

```auto
{
    "script" : {
        "source": "ctx._source.tags.add(params.att)",
        "lang": "painless",
        "params" : {
            "att" : {
            	"data": "seven"
            }
        }
    }
}

```

and then I post like:  
test/\_update/AaCnJ3IBeJO1gLa1SX7H

```auto
{
    "doc" : {
        "name": "Walter"
    }
}

```

---

<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: [June 15, 2020, 1:02pm UTC](https://discuss.elastic.co/t/best-way-to-update-and-insert-array/233109/2 "2020-06-15T13:02:16Z")

</div>

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