How to duplicate every document in an index

Hello. I would like to duplicate every document I have in my index, changing the value of a single field for each new duplicated document. How would I do this?

properly the best to use the reindex api with a script
something like: (no guarantee that it works exactly like that - not tested)

POST _reindex?wait_for_completion=true&refresh=true
{
  "source": {
    "index": "xxx"
  },
  "dest": {
    "index": "xxx"
  }
  ,"script": {
    "source": "ctx._id=null; ctx._source.<fieldname>=<new_value>;"
  }
}

if you are not reindexing into the same index you can remove the first part ctx._id=null;

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