# Recreate index, error 'resource\_already\_exists\_exception'

**URL:** <https://discuss.elastic.co/t/recreate-index-error-resource-already-exists-exception/365105>\
**Category:** Elasticsearch\
**Created:** [August 19, 2024, 6:35am UTC](https://discuss.elastic.co/t/recreate-index-error-resource-already-exists-exception/365105 "2024-08-19T06:35:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LiJie20190102](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lijie20190102/32/136871_2.png) [@LiJie20190102](https://discuss.elastic.co/u/LiJie20190102)\
**Post date:** [August 19, 2024, 6:35am UTC](https://discuss.elastic.co/t/recreate-index-error-resource-already-exists-exception/365105/1 "2024-08-19T06:35:42Z")

</div>

My goal is to quickly clear the index, but I found that the 'delete-by\_query' courier is slow, so I plan to delete it first and then create a new index like before, but I find that errors often occur：

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/1/51113ac3962e34adbfd6b78f7322339b8b4d5c6d.png)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 19, 2024, 6:48am UTC](https://discuss.elastic.co/t/recreate-index-error-resource-already-exists-exception/365105/2 "2024-08-19T06:48:03Z")

</div>

Welcome!

Please don't post images of text as they are hard to read, may not display correctly for everyone, and are not searchable.

Instead, paste the text and format it with `</>` icon or pairs of triple backticks (```), and check the preview window to make sure it's properly formatted before posting it. This makes it more likely that your question will receive a useful answer.

It would be great if you could update your post to solve this.

This message indicates that the index `lj_test1` already exists.  
You need to describe a bit more what calls you are doing.

Normally, running:

```auto
DELETE lj_test1
PUT lj_test1

```

should not cause that.

Which version are you using?

---

<div class="post-metadata">

**Author:** ![LiJie20190102](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lijie20190102/32/136871_2.png) [@LiJie20190102](https://discuss.elastic.co/u/LiJie20190102)\
**Post date:** [August 19, 2024, 7:05am UTC](https://discuss.elastic.co/t/recreate-index-error-resource-already-exists-exception/365105/3 "2024-08-19T07:05:10Z")

</div>

Sorry, this is my first time using this community and I am not yet proficient.

### Elasticsearch Version

7.17.21

### Installed Plugins

_No response_

### Java Version

21.0.2

### OS Version

3.10.0-862.el7.x86\_64 [#1](https://github.com/elastic/elasticsearch/issues/1) SMP Fri Apr 20 16:44:24 UTC 2018 x86\_64 x86\_64 x86\_64 GNU/Linux

### Problem Description

My goal is to quickly clear the index, but I found that the 'delete-by\_query' courier is slow, so I plan to delete it first and then create a new index like before, but I find that errors often occur：

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/1/51113ac3962e34adbfd6b78f7322339b8b4d5c6d.png)

### Steps to Reproduce

1. create index

```auto
PUT / lj_test1 {
	"settings": {
		"number_of_shards": 10,
		"number_of_replicas": 6
	},
	"mappings": {
		"properties": {
			"name1": {
				"type": "text"
			},
			"name2": {
				"type": "text"
			},
			"name3": {
				"type": "text"
			},
			"name4": {
				"type": "text"
			},
			"name5": {
				"type": "text"
			},
			"name6": {
				"type": "text"
			}
		}
	}
}

```

1. Delete index

```auto
DELETE /lj_test1

```

1. After completing step 2, quickly re execute step 1

**note** : If not reproduced, please increase the number of **shards** and **replicas** slightly

### Logs

{  
"error" : {  
"root\_cause" : [  
{  
"type" : "resource\_already\_exists\_exception",  
"reason" : "index [lj\_test1/wWP6JOWvSL2mRePTHQ4YDQ] already exists",  
"index\_uuid" : "wWP6JOWvSL2mRePTHQ4YDQ",  
"index" : "lj\_test1"  
}  
],  
"type" : "resource\_already\_exists\_exception",  
"reason" : "index [lj\_test1/wWP6JOWvSL2mRePTHQ4YDQ] already exists",  
"index\_uuid" : "wWP6JOWvSL2mRePTHQ4YDQ",  
"index" : "lj\_test1"  
},  
"status" : 400  
}

I described it in the ES issue before, please refer to this ([Recreate index, error 'resource\_already\_exists\_exception' · Issue #111945 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/111945)) for details

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [August 19, 2024, 7:25am UTC](https://discuss.elastic.co/t/recreate-index-error-resource-already-exists-exception/365105/4 "2024-08-19T07:25:22Z")

</div>

What is the specification of your cluster? How many nodes? How much CPU, RAM and heap do you have assigned? What type of storage are you using?

If you can not resolve this a possible workaround would be to create an alias that sits in front of the index. Having this allows you to clear the index using the following steps:

1. At the start the alias A points to the existing index A1, which holds the data you want to clear.
2. Create a new, empty backing index A2 with the correct mapping.
3. In a single operation remove the alias A from A1 and add it to index A2.
4. Remove the A1 index.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [August 19, 2024, 7:36am UTC](https://discuss.elastic.co/t/recreate-index-error-resource-already-exists-exception/365105/5 "2024-08-19T07:36:40Z")

</div>

> [@LiJie20190102](#):
>
> I described it in the ES issue before, please refer to this ([Recreate index, error 'resource\_already\_exists\_exception' · Issue #111945 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/111945)) for details

As I mentioned in the issue, I think the problem is that you are not waiting for a _successful_ response from the delete step. I cannot reproduce this. Please share the output from all three API calls, rather than just the last one.
