How to reindex , with multiple _id in index

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 but it is for one index. How to do that?

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

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

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

I am using command to reindex:

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?

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?

"_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

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?

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

Could you answer that ^^^ then?

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.

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?

Yes it is multiplied by 12345.

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

Thanks David for your suggestion, My problem got resolved.

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