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...
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:
- GET the document
- Create a new empty instance of document
- 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 ofsource_index - Using Reindex API, reindex that particular document from
source_indextodesitnation_index. During this operation, update the _id (I've mentioned the script) - Reindex this document back from
desitnation_indextosource_index