# Is there a way to merge two indices

**URL:** <https://discuss.elastic.co/t/is-there-a-way-to-merge-two-indices/315980>\
**Category:** Elasticsearch\
**Tags:** reindex\
**Created:** [October 6, 2022, 1:39pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-merge-two-indices/315980 "2022-10-06T13:39:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dedsec0](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dedsec0/32/111752_2.png) [@Dedsec0](https://discuss.elastic.co/u/Dedsec0)\
**Post date:** [October 6, 2022, 1:39pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-merge-two-indices/315980/1 "2022-10-06T13:39:20Z")

</div>

Hi, I want to merge two indices( index 1, index 2) and make as one index( index 3),

`For instance` : let say, I have index 1 and index 2 have matching fields like ...

```auto
index 1 :(doc count 1)
	{
		"operation": "add",
		"time" : 1-4-2022,
	}

```

```auto
index 2:(doc count 2)
	{
		"operation" : "add",
		"time " : 21-10-2022,
		"description" : "hehhehehe"
	},
	{
		"operation" : "delete",
		"time " : 1-3-2022,
		"description" : "meh"
	}

```

now i want to create another index( index 3 ) that merges these two indices

```auto
index 3: (doc count 2)
	{
		"operation" : "add",
		"time " : 21-10-2022
	},
	{
		"operation" : "delete",
		"time " : 1-3-2022,
		"description" : "meh"
	}

```

```auto
Note : above example I matched the document using "operation" if the operation matches then it will update "time" field only(or the field that i want to update),
and if the "operation" field is now like above example "delete" then it will create a new document in index 3.

```

is there any way that I can achieve this ? (edited)

---

<div class="post-metadata">

**Author:** ![EmaysHRT](https://avatars.discourse-cdn.com/v4/letter/e/8c91f0/32.png) [@EmaysHRT](https://discuss.elastic.co/u/EmaysHRT)\
**Post date:** [October 6, 2022, 4:17pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-merge-two-indices/315980/2 "2022-10-06T16:17:50Z")

</div>

You can use [the reindex API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html) to achieve this. It will copy the documents from index 1 and index 2 into index 3, and you can then delete the old indices.

---

<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:** [November 3, 2022, 4:18pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-merge-two-indices/315980/3 "2022-11-03T16:18:07Z")

</div>

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