# Merge 2 indexes in one with same id

**URL:** <https://discuss.elastic.co/t/merge-2-indexes-in-one-with-same-id/179526>\
**Category:** Elasticsearch\
**Created:** [May 3, 2019, 11:24am UTC](https://discuss.elastic.co/t/merge-2-indexes-in-one-with-same-id/179526 "2019-05-03T11:24:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![olpru](https://avatars.discourse-cdn.com/v4/letter/o/d6d6ee/32.png) [@olpru](https://discuss.elastic.co/u/olpru)\
**Post date:** [May 3, 2019, 11:24am UTC](https://discuss.elastic.co/t/merge-2-indexes-in-one-with-same-id/179526/1 "2019-05-03T11:24:46Z")

</div>

Hello,

I try to merge 2 indexes into one.  
The first index (index\_1) looks like this:

```
{
        "_index" : "index_1",
        "_id" : "1",
        "_source" : {
            "a":"1"
        }
      },
{
        "_index" : "index_1",
        "_id" : "2",
        "_source" : {
            "a":"2"
        }
}

```

The second index (index\_2) looks like this:

```
  {
        "_index" : "index_2",
        "_id" : "1",
        "_source" : {
            "a":"3"
    }
}

```

Now I want to merge this two indexes into a new index (index\_1\_2):

```
{
        "_index" : "index_1_2",
        "_id" : "1",
        "_source" : {
            "a":"3"
        }
      },
{
        "_index" : "index_1_2",
        "_id" : "2",
        "_source" : {
            "a":"2"
        }
}

```

In older versions (\< 7.0.0) for me the reindex was working:

```
POST _reindex
{
  "source": {
    "index": ["index_1", "index_2"]
},
  "dest": {
    "index": "index_1_2"
  }
}

```

But this is not working anymore. In the documentation ([https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html))  
is for this reindexing the following note:  
"The Reindex API makes no effort to handle ID collisions so the last document written will "win" but the order isn’t usually predictable so it is not a good idea to rely on this behavior. Instead, make sure that IDs are unique using a script."

How can I solve this problem?

Thank you!  
Oliver

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 6, 2019, 12:10am UTC](https://discuss.elastic.co/t/merge-2-indexes-in-one-with-same-id/179526/2 "2019-05-06T00:10:23Z")

</div>

Is the assumption that the document with the higher value for `a` is the one that you want?

---

<div class="post-metadata">

**Author:** ![olpru](https://avatars.discourse-cdn.com/v4/letter/o/d6d6ee/32.png) [@olpru](https://discuss.elastic.co/u/olpru)\
**Post date:** [May 6, 2019, 4:57am UTC](https://discuss.elastic.co/t/merge-2-indexes-in-one-with-same-id/179526/3 "2019-05-06T04:57:31Z")

</div>

Hi Mark,

yes, I want in index\_1\_2 the value a="3" from index\_2.  
index\_2 is a subset of index\_1. In the index\_2 are only documents which have changes from index\_1.

Best regards  
Oliver

---

<div class="post-metadata">

**Author:** ![olpru](https://avatars.discourse-cdn.com/v4/letter/o/d6d6ee/32.png) [@olpru](https://discuss.elastic.co/u/olpru)\
**Post date:** [May 8, 2019, 9:06am UTC](https://discuss.elastic.co/t/merge-2-indexes-in-one-with-same-id/179526/4 "2019-05-08T09:06:56Z")

</div>

Hello,

does anyone have a solution for that issue?

Best regards  
Oliver

---

<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 5, 2019, 9:06am UTC](https://discuss.elastic.co/t/merge-2-indexes-in-one-with-same-id/179526/5 "2019-06-05T09:06:58Z")

</div>

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