# Merge matching documents

**URL:** <https://discuss.elastic.co/t/merge-matching-documents/288959>\
**Category:** Elasticsearch\
**Created:** [November 11, 2021, 7:51am UTC](https://discuss.elastic.co/t/merge-matching-documents/288959 "2021-11-11T07:51:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![samhagin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/samhagin/32/77283_2.png) [@samhagin](https://discuss.elastic.co/u/samhagin)\
**Post date:** [November 11, 2021, 7:51am UTC](https://discuss.elastic.co/t/merge-matching-documents/288959/1 "2021-11-11T07:51:09Z")

</div>

I have two different indices with matching documents - the \_id field is the same. How can I copy documents from one index to another and overwrite the document at the destination, and also insert a document if it doesn't exist?

For instance, this document exists on both indices with a slight variation

**index\_one**

```auto
          "_id" : "12345678",
          "time" : 1625029200000,
          "amount" : "0.26",
          "description" : "bag of rice",

```

**index\_two**

```auto
          "_id" : "12345678",
          "time" : 1825029200000,
          "amount" : "0.57",
          "description" : "beans",

```

I want to copy the document above from **index\_one** and since the \_id matches, overwrite the fields in **index\_two** with those that exist on **index\_one**. What is the best way to achieve this? Reindexing will copy documents that do not exist from the source to the destination but won't overwrite existing documents.

---

<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:** [December 9, 2021, 7:51am UTC](https://discuss.elastic.co/t/merge-matching-documents/288959/2 "2021-12-09T07:51:45Z")

</div>

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