# ElasticSearch partial update request merge Map\<\>

**URL:** https://discuss.elastic.co/t/elasticsearch-partial-update-request-merge-map/362559
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [July 4, 2024, 1:42pm UTC](https://discuss.elastic.co/t/elasticsearch-partial-update-request-merge-map/362559 "2024-07-04T13:42:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![nolik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nolik/32/135792_2.png) [@nolik](https://discuss.elastic.co/u/nolik)
#### Post date: [July 4, 2024, 1:42pm UTC](https://discuss.elastic.co/t/elasticsearch-partial-update-request-merge-map/362559/1 "2024-07-04T13:42:02Z")

</div>

I have a complex ES document with multiple fields:

```auto
public class SomeDocument {
  @JsonProperty("id")
  private final String id;
  ...
  @JsonProperty("hits")
  private final Map<String, Double> hits = new HashMap<>();
}

```

hits stored in the schema as

```auto
 "template": {
    "mappings": {
      "properties": {
        "id": {
          "type": "keyword"
        },
        "hits": {
          "type": "flattened"
        }
}

```

I'm using elasticsearch-java-8.10.4 client and Partial update to update the document (it contains many fields and I'm interested in updating only some).

```auto
    // Create the update request
    Map<String, Object> partialDoc = new HashMap<>();
    partialDoc.put("hits", Map.of("testHit", 1.0));
    UpdateRequest<SomeDocument, Map<String, Object>> updateRequest =
        UpdateRequest.of(u -> u.index(indexName).id(documentId).doc(partialDoc));

    // Execute the update
      UpdateResponse<SomeDocument> updateResponse =
          esClient.update(updateRequest, SomeDocument.class);
  }

```

But after the update instead of overriding the Hit field with only new values ES merge them into an aggregated Map with previous Map values and new Map entry.  
SO the result of the partial update returned hits in document:

```auto
hits={"oldHit"=1.0, "testHit"=1.0}

```

At the same time with other fields that under the hood use Set or List collections - all updates override old data from collections.  
Probably someone faced similar behaviour with the partial update of the Maps? and know how to mediate this issue (with continued of use the partial update and ideally without script use)

---

<div class="post-metadata">

### Author: ![Carlos\_D](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carlos_d/32/126245_2.png) [@Carlos\_D](https://discuss.elastic.co/u/Carlos_D)
#### Post date: [July 5, 2024, 12:00pm UTC](https://discuss.elastic.co/t/elasticsearch-partial-update-request-merge-map/362559/2 "2024-07-05T12:00:20Z")

</div>

From #Elastic Search to #Elasticsearch

---

<div class="post-metadata">

### Author: ![Carlos\_D](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carlos_d/32/126245_2.png) [@Carlos\_D](https://discuss.elastic.co/u/Carlos_D)
#### Post date: [July 5, 2024, 12:00pm UTC](https://discuss.elastic.co/t/elasticsearch-partial-update-request-merge-map/362559/3 "2024-07-05T12:00:20Z")

</div>

Added #language-clients

---

<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: [August 2, 2024, 12:00pm UTC](https://discuss.elastic.co/t/elasticsearch-partial-update-request-merge-map/362559/4 "2024-08-02T12:00:51Z")

</div>

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