# How to change \_id as GUID during reindex

**URL:** <https://discuss.elastic.co/t/how-to-change-id-as-guid-during-reindex/182552>\
**Category:** Elasticsearch\
**Created:** [May 24, 2019, 4:32am UTC](https://discuss.elastic.co/t/how-to-change-id-as-guid-during-reindex/182552 "2019-05-24T04:32:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SudevPK](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@SudevPK](https://discuss.elastic.co/u/SudevPK)\
**Post date:** [May 24, 2019, 4:32am UTC](https://discuss.elastic.co/t/how-to-change-id-as-guid-during-reindex/182552/1 "2019-05-24T04:32:17Z")

</div>

I have two different elastic search nodes.I need to reindex 10 indices from one node to 1 index in another node.But there is not unique id's in the 10 indices, so i need to generate \_id as GUID while reindexing

---

<div class="post-metadata">

**Author:** ![SudevPK](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@SudevPK](https://discuss.elastic.co/u/SudevPK)\
**Post date:** [May 28, 2019, 6:51am UTC](https://discuss.elastic.co/t/how-to-change-id-as-guid-during-reindex/182552/2 "2019-05-28T06:51:42Z")

</div>

Hi Team,  
Is the above is possible using elastic search ?

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [May 28, 2019, 8:38am UTC](https://discuss.elastic.co/t/how-to-change-id-as-guid-during-reindex/182552/3 "2019-05-28T08:38:40Z")

</div>

Hi,

As I understand your problem you have documents in different index with the same id, and you want to save them in a unique index without loosing your document?

Here 2 documents with similar id in 2 different index

```
POST twitter/doc/1
{
  "name": "abc"
}

POST twitter2/doc/1
{
  "name": "def"
}

```

Run \_reindex with removing \_id from the source so elastic will set a new id  
**EDIT** : you can reindex with one call by settings the list of your source index.

From reindex doc page: [Reindex API | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)

> `index` in `source` can be a list, allowing you to copy from lots of sources in one request.

```
POST _reindex
{
  "source": {
    "index": ["twitter", "twitter2"]
  },
  "dest": {
    "index": "new_twitter"
  },
  "script": {
    "source": "ctx._id=null",
    "lang": "painless"
  }
}

```

Running a get on the new index

```
GET new_twitter/_search

```

Will return:

```
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "new_twitter",
        "_type" : "doc",
        "_id" : "fg6M_WoBShLPuKD8afVc",
        "_score" : 1.0,
        "_source" : {
          "name" : "abc"
        }
      },
      {
        "_index" : "new_twitter",
        "_type" : "doc",
        "_id" : "XQ6M_WoBShLPuKD8p_ka",
        "_score" : 1.0,
        "_source" : {
          "name" : "def"
        }
      }
    ]
  }

```

According to the documentation:

> **[Reindex API | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)**

> Think of the possibilities! Just be careful; you are able to change:
> 
> - `_id`
> - `_index`
> - `_version`
> - `_routing`
> 
> Setting `_version` to `null` or clearing it from the `ctx` map is just like not sending the version in an indexing request;

So set ctx.\_id=null remove the value and on insert Elastic will set a new value.

---

<div class="post-metadata">

**Author:** ![SudevPK](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@SudevPK](https://discuss.elastic.co/u/SudevPK)\
**Post date:** [May 28, 2019, 8:42am UTC](https://discuss.elastic.co/t/how-to-change-id-as-guid-during-reindex/182552/4 "2019-05-28T08:42:37Z")

</div>

@gabriel_tessier Thank you so much 🙂

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [May 29, 2019, 3:43am UTC](https://discuss.elastic.co/t/how-to-change-id-as-guid-during-reindex/182552/5 "2019-05-29T03:43:34Z")

</div>

Just for information i edited my previous post, replaced the 2 \_reindex call with one.

---

<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 26, 2019, 3:43am UTC](https://discuss.elastic.co/t/how-to-change-id-as-guid-during-reindex/182552/6 "2019-06-26T03:43:38Z")

</div>

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