# How to update an array using JAVA api?

**URL:** https://discuss.elastic.co/t/how-to-update-an-array-using-java-api/89788
**Category:** Elasticsearch
**Created:** [June 17, 2017, 12:08am UTC](https://discuss.elastic.co/t/how-to-update-an-array-using-java-api/89788 "2017-06-17T00:08:56Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![kaushah](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kaushah](https://discuss.elastic.co/u/kaushah)
#### Post date: [June 17, 2017, 12:08am UTC](https://discuss.elastic.co/t/how-to-update-an-array-using-java-api/89788/1 "2017-06-17T00:08:56Z")

</div>

How do I achieve the following in Java api?

```
POST test/type1/1/_update
{
    "script" : {
        "inline": "ctx._source.tags.add(params.tag)",
        "lang": "painless",
        "params" : {
            "tag" : "blue"
        }
    }
}

```

The current document is:

```
PUT test/type1/1
{
    "counter" : 1,
    "tags" : ["red"]
}
```

---

<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: [July 15, 2017, 12:08am UTC](https://discuss.elastic.co/t/how-to-update-an-array-using-java-api/89788/2 "2017-07-15T00:08:57Z")

</div>

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