# How to duplicate every document in an index

**URL:** <https://discuss.elastic.co/t/how-to-duplicate-every-document-in-an-index/194328>\
**Category:** Elasticsearch\
**Created:** [August 7, 2019, 9:06pm UTC](https://discuss.elastic.co/t/how-to-duplicate-every-document-in-an-index/194328 "2019-08-07T21:06:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TeraInferno](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/terainferno/32/40302_2.png) [@TeraInferno](https://discuss.elastic.co/u/TeraInferno)\
**Post date:** [August 7, 2019, 9:06pm UTC](https://discuss.elastic.co/t/how-to-duplicate-every-document-in-an-index/194328/1 "2019-08-07T21:06:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Shaoranlaos](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Shaoranlaos](https://discuss.elastic.co/u/Shaoranlaos)\
**Post date:** [August 8, 2019, 5:13am UTC](https://discuss.elastic.co/t/how-to-duplicate-every-document-in-an-index/194328/2 "2019-08-08T05:13:44Z")

</div>

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

```auto
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;`

---

<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:** [September 5, 2019, 5:13am UTC](https://discuss.elastic.co/t/how-to-duplicate-every-document-in-an-index/194328/3 "2019-09-05T05:13:49Z")

</div>

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