# Elasticsearch: update existing document by inserting elements to its array fields

**URL:** <https://discuss.elastic.co/t/elasticsearch-update-existing-document-by-inserting-elements-to-its-array-fields/360905>\
**Category:** Elasticsearch\
**Created:** [June 6, 2024, 4:20am UTC](https://discuss.elastic.co/t/elasticsearch-update-existing-document-by-inserting-elements-to-its-array-fields/360905 "2024-06-06T04:20:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Satyam\_Kaushik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/satyam_kaushik/32/123759_2.png) [@Satyam\_Kaushik](https://discuss.elastic.co/u/Satyam_Kaushik)\
**Post date:** [June 6, 2024, 4:20am UTC](https://discuss.elastic.co/t/elasticsearch-update-existing-document-by-inserting-elements-to-its-array-fields/360905/1 "2024-06-06T04:20:56Z")

</div>

Consider the following document

```auto
{
  "title": "My first blog entry",
  "text": "Starting to get the hang of this...",
  "tags": ["testing"], 
  "views": 0 
}

```

I need to run kind of an upsert operation. If I encounter data like

```auto
{
    "id": 1,
    "tags": ["new tag"]
}

```

I want to update the existing document with same id. So result should be :

```auto
{
    "id": 1,
    "title": "My first blog entry",
    "text": "Starting to get the hang of this...",
    "tags": ["testing", "new tag"], 
    "views": 0 
}

```

If the document with same id does not exist, I want to create a new one.

In Solr I could do this using Atomic updates. Is there a way to do this in Elasticsearch using Bulk API in Java?
