# How to reindex , with multiple \_id in index

**URL:** <https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879>\
**Category:** Elasticsearch\
**Created:** [January 10, 2018, 1:26pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879 "2018-01-10T13:26:47Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhishekh](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@Abhishekh](https://discuss.elastic.co/u/Abhishekh)\
**Post date:** [January 10, 2018, 1:26pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879/1 "2018-01-10T13:26:47Z")

</div>

Hi,  
I have Index with more than one document and wanted to reindex but while reindexing wanted to change the \_id field of each document in destination index. Followed[this](https://discuss.elastic.co/t/how-to-change-a-documents--id-during-a-reindex/76132) but it is for one index. How to do that?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 10, 2018, 1:28pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879/2 "2018-01-10T13:28:11Z")

</div>

I'm unsure but may be you can modify `ctx._source._index`?

---

<div class="post-metadata">

**Author:** ![Abhishekh](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@Abhishekh](https://discuss.elastic.co/u/Abhishekh)\
**Post date:** [January 10, 2018, 1:30pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879/3 "2018-01-10T13:30:29Z")

</div>

Thanks for your suggestion but wanted to modify the \_id not \_index. For one document we can change the \_id while reindexing and my case is for multiple docs

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 10, 2018, 1:49pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879/4 "2018-01-10T13:49:42Z")

</div>

So I don't understand. Why `ctx._source._id` does not work in your case?

---

<div class="post-metadata">

**Author:** ![Abhishekh](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@Abhishekh](https://discuss.elastic.co/u/Abhishekh)\
**Post date:** [January 10, 2018, 2:10pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879/5 "2018-01-10T14:10:21Z")

</div>

I am using command to reindex:

```auto
curl -XPOST 'localhost:9200/_reindex?pretty' -H 'Content-Type: application/json' -d'
{
	"source": {
    "index": "megacorp"
  },
  "dest": {
    "index": "tempindex"
  },

    "script" : {
    "inline": "ctx._id= 12345"
  }
}
'

```

After successful execution it copies the megacorp/type/1( where 1 is \_id ) document to tempindex/type/1234. As I could not found to give the source \_id field in command so by default it is taking first document in this case \_id =1 and copies the document in the destination \_id =1234. As source index megacorp contains many documents but it copies only one to tempindex. Is there any way to give the source \_id while reindexing?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 10, 2018, 2:26pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879/6 "2018-01-10T14:26:18Z")

</div>

> Is there any way to give the source \_id while reindexing?

Which value you want to set the id to? Is that from a field which is available within your document?

---

<div class="post-metadata">

**Author:** ![Abhishekh](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@Abhishekh](https://discuss.elastic.co/u/Abhishekh)\
**Post date:** [January 10, 2018, 3:13pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879/7 "2018-01-10T15:13:23Z")

</div>

"\_index" : "megacorp1",  
"\_type" : "employee",  
"\_id" : "2",  
"\_version" : 1,  
"result" : "created",  
"\_shards" : {  
"total" : 2,  
"successful" : 1,  
"failed" : 0

I want to give all \_id value from existing document as a source and a destination \_id's for new index. As given above \_id is 2 so in new index i want to copy this document to other index suppose 12 like this while reindexing wanted to copy document from source index to destination index at different \_id

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 10, 2018, 3:39pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879/8 "2018-01-10T15:39:23Z")

</div>

So if I understand correctly you have a document which coordinate is:

```
source/doc/1

```

And you want to reindex it as

```
destination/doc/12

```

Do I understand correctly the requirement?  
If so, tell me how you compute `12` from the data you have in document `1`. Where this `12` number is coming from?

---

<div class="post-metadata">

**Author:** ![Abhishekh](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@Abhishekh](https://discuss.elastic.co/u/Abhishekh)\
**Post date:** [January 10, 2018, 3:52pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879/9 "2018-01-10T15:52:16Z")

</div>

Yes U have understood the requirement correctly David. As per my project requirement I need to copy the document to different id in destination index

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 10, 2018, 4:08pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879/10 "2018-01-10T16:08:47Z")

</div>

> [@dadoonet](#):
>
> If so, tell me how you compute 12 from the data you have in document 1. Where this 12 number is coming from?

Could you answer that ^^^ then?

---

<div class="post-metadata">

**Author:** ![Abhishekh](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@Abhishekh](https://discuss.elastic.co/u/Abhishekh)\
**Post date:** [January 10, 2018, 4:12pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879/11 "2018-01-10T16:12:13Z")

</div>

```auto
curl -XPOST 'localhost:9200/_reindex?pretty' -H 'Content-Type: application/json' -d'
{
	"source": {
    "index": "megacorp"
  },
  "dest": {
    "index": "tempindex"
  },

    "script" : {
    "inline": "ctx._id= 12345"
  }
}
'

```

As in this it is copying \_id 1 data to 12345 at destination similarly as per requirement I have to insert at any \_id in destination.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 10, 2018, 4:28pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879/12 "2018-01-10T16:28:17Z")

</div>

What is "any `_id`"? Again, how do you compute this `12345`? Is it the current `_id` of the document multiplied by `12345`? What is the rule to get that number?

---

<div class="post-metadata">

**Author:** ![Abhishekh](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@Abhishekh](https://discuss.elastic.co/u/Abhishekh)\
**Post date:** [January 10, 2018, 4:32pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879/13 "2018-01-10T16:32:47Z")

</div>

Yes it is multiplied by 12345.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 10, 2018, 4:35pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879/14 "2018-01-10T16:35:22Z")

</div>

Then can you write: `ctx._id = ctx._id * 12345`?

---

<div class="post-metadata">

**Author:** ![Abhishekh](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@Abhishekh](https://discuss.elastic.co/u/Abhishekh)\
**Post date:** [January 10, 2018, 5:01pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879/16 "2018-01-10T17:01:44Z")

</div>

Thanks David for your suggestion, My problem got resolved.

---

<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:** [February 7, 2018, 5:01pm UTC](https://discuss.elastic.co/t/how-to-reindex-with-multiple-id-in-index/114879/17 "2018-02-07T17:01:48Z")

</div>

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