-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recreate index, error 'resource_already_exists_exception' #111945
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
I used your method from the beginning. I implemented it using Java code, but the exists method shows that the index does not exist. I think the delete method I am using is synchronous, and by the time delete is executed, the index will definitely no longer exist. |
I can't reproduce this. I wrote the following test case to do as you suggest and it does not fail: diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java
index 27f0cd408e7f..59ce76130d43 100644
--- a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java
+++ b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java
@@ -21,6 +21,7 @@ import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
+import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetadata;
@@ -36,10 +37,12 @@ import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.indices.IndicesService;
+import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.ESIntegTestCase.Scope;
import org.elasticsearch.test.rest.ESRestTestCase;
+import org.elasticsearch.xcontent.ToXContentFragment;
import org.elasticsearch.xcontent.XContentFactory;
import java.io.IOException;
@@ -418,4 +421,44 @@ public class CreateIndexIT extends ESIntegTestCase {
assertTrue((boolean) extractValue("acknowledged", entityAsMap(response)));
}
+ public void testAlreadyExistsAfterDelete() throws IOException {
+ final var restClient = getRestClient();
+
+ final ToXContentFragment createRequestBody = (builder, params) -> builder.startObject("settings")
+ .field("number_of_shards", 10)
+ .field("number_of_replicas", 6)
+ .endObject()
+ .startObject("mappings")
+ .startObject("properties")
+ .startObject("name1")
+ .field("type", "text")
+ .endObject()
+ .startObject("name2")
+ .field("type", "text")
+ .endObject()
+ .startObject("name3")
+ .field("type", "text")
+ .endObject()
+ .startObject("name4")
+ .field("type", "text")
+ .endObject()
+ .startObject("name5")
+ .field("type", "text")
+ .endObject()
+ .startObject("name6")
+ .field("type", "text")
+ .endObject()
+ .endObject()
+ .endObject();
+
+ for (int i = 0; i < 10; i++) {
+ final var createResponse = restClient.performRequest(
+ ESRestTestCase.newXContentRequest(HttpMethod.PUT, "/lj_test1", createRequestBody)
+ );
+ assertEquals(RestStatus.OK.getStatus(), createResponse.getStatusLine().getStatusCode());
+
+ final var deleteResponse = restClient.performRequest(new Request("DELETE", "/lj_test1"));
+ assertEquals(RestStatus.OK.getStatus(), deleteResponse.getStatusLine().getStatusCode());
+ }
+ }
} As it doesn't seem to be reproducible and could well be caused by an error in your test (e.g. not waiting for a successful response from the There's an active community in the forum that should be able to help get an answer to your question. As such, I hope you don't mind that I close this. |
I am certain that I waited for the delete to complete before continuing to create the index, which I believe may be related to my limited environmental resources. Because my previous code also waited for delete to complete before recreating the index. My overall goal is to clear the data in the index. Is my method the fastest in terms of performance |
This isn't the right place to continue this discussion. Please use the forum. |
Elasticsearch Version
7.17.21
Installed Plugins
No response
Java Version
21.0.2
OS Version
3.10.0-862.el7.x86_64 #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:
Steps to Reproduce
create index
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" } } } }
Delete index
DELETE /lj_test1
After completing step 2, quickly re execute step 1
note: If not reproduced, please increase the number of shards and replicas slightly
Logs (if relevant)
{
"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
}
The text was updated successfully, but these errors were encountered: