Duplicate a Document on Elasticsearch

I need to clone the content of a document in my elasticsearch index (in the same index) by using the kibana console. I need exactly the same fields in the _source of the document (of course, the copy will have another id). I tryed to:

  1. GET the document
  2. Create a new empty instance of document
  3. Update the new document by manually copying the properties of the result on (1):
POST /blog/post/VAv2FWoBKgnBpki61WiD/_update {    "doc" : {
  "content" : "..." ...

But the problem is the field contain veeeery long properties. And sometimes I got an error since the strings seem not to be scaped when I manually copy them from the Kibana interface.

I searched in the documentation but I can not find a query to duplicate a document, and it is a quite common think to do I think...

Any clue?

1 Answer

Make use of Reindex API. Here is what you can do.

Summary of steps:

  • Create a destination_index (dummy). Make sure the mapping is exact to that of source_index
  • Using Reindex API, reindex that particular document from source_index to desitnation_index. During this operation, update the _id (I've mentioned the script)
  • Reindex this document back from desitnation_index to source_index
Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.