-
Notifications
You must be signed in to change notification settings - Fork 25k
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
If the index does not exist, delete document will not auto create it #24518
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ElasticsearchException exception = expectThrows(ElasticsearchException.class, | ||
() -> execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync)); | ||
assertEquals(RestStatus.NOT_FOUND, exception.status()); | ||
assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index]", exception.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of this test is to check how delete behaves where it doesn't find the document in question. I don't think there is a need to test the index creation on the rest client tests (this is done in the core testing). Just create the index and let the test what it does.
@@ -223,6 +228,18 @@ public void testDelete() { | |||
assertSameIndices(deleteRequest, deleteShardActions); | |||
} | |||
|
|||
// for delete index throws an IndexNotFoundException if the index does not exist or create the index if external version is used | |||
public void testDeleteAction() throws InterruptedException, ExecutionException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the wrong place for this - this suite checks that index names are passed correctly to sub request. IMO you should create a unit test TransportBulkActionTests
class, which inherits from ESTestCase
and test how the TransportBulkAction
decides which indices need to be auto created. You can look at how TransportBulkActionIngestTests.TestTransportBulkAction
is set up as an example. Let me know if you need more guidance and I'm happy to help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bleskes thanks for the tip, I will add a TransportBulkActionTests
.
Hm... It appeared to me that at the time the issue was opened, the delete
was not using BulkAction
( based on some comments ). So I decided to add the test here to verify that explicitly using the delete
endpoint will not create the index. But of course I can remove it ;)
@@ -68,7 +68,7 @@ public void testAllFail() { | |||
bulkRequest.add(new IndexRequest("can't")); | |||
bulkRequest.add(new DeleteRequest("do")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe change this to a delete request with an external version?
docs/reference/docs/delete.asciidoc
Outdated
@@ -105,7 +105,8 @@ thrown instead. | |||
[[delete-index-creation]] | |||
=== Automatic index creation | |||
|
|||
The delete operation automatically creates an index if it has not been | |||
If external version is used, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you mention external_gte too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding a link here as there are actually 3 external version types : external
, external_gt
and external_gte
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with something generic here (if one of the external versioning variants is used) and linking to the versioning page.
unless an external versioning is used
dfa2725
to
bc5efd8
Compare
@bleskes thank you for your review! I just pushed the changes you suggested. |
bc5efd8
to
c44d565
Compare
reverting the changes to the REST client tests and the IndicesRequestIT add a section to the indices.asciidoc
c44d565
to
0ab6b95
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. I left some very minor requests.
@@ -65,6 +64,11 @@ | |||
public void testDelete() throws IOException { | |||
{ | |||
// Testing non existing document | |||
final XContentType xContentType = randomFrom(XContentType.values()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was this added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not figure out how else to explicitly create an index in the REST client... Do you have a suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you still need to use the low level client for that, using client().performRequest()
. That said, why not change the order of the test blocks around and move the // Testing deletion
block to be first. It will create the index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, duh! 😊 Thanks @bleskes!
@@ -144,6 +145,9 @@ protected void doExecute(Task task, BulkRequest bulkRequest, ActionListener<Bulk | |||
// Attempt to create all the indices that we're going to need during the bulk before we start. | |||
// Step 1: collect all the indices in the request | |||
final Set<String> indices = bulkRequest.requests.stream() | |||
.filter(request -> request.opType() != DocWriteRequest.OpType.DELETE | |||
|| request.versionType() == VersionType.EXTERNAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment here as to why we have a special handling for external versions and deletes here?
@@ -66,6 +66,7 @@ | |||
import org.elasticsearch.action.index.IndexRequest; | |||
import org.elasticsearch.action.search.SearchRequest; | |||
import org.elasticsearch.action.search.SearchResponse; | |||
import org.elasticsearch.action.search.SearchTransportService; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: left over formatting.. can you please remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... you want me revert and leave the imports not organized?
In general I agree that major reformatting should happen separately but it is just a single import ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hear you. On the other hand, it's just a reset to commit away :)
super.tearDown(); | ||
} | ||
|
||
public void testDeleteNonExistingDoc() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we call this testDeleteNonExistingDocDoesNotCreateIndices
})); | ||
} | ||
|
||
public void testDeleteNonExistingDocExternalVersion() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment about naming. Can we add "CreatesIndex"?
fc60911
to
fa39cef
Compare
@bleskes thanks for the remarks! Do you know how I can simply create an index in the REST client? |
thanks a lot @olcbean . I'll merge this in. |
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
Currently a
delete document
request against a non-existing index actually creates this index.With this change the
delete document
no longer creates the previously non-existing index and throws anindex_not_found
exception instead.However as discussed in #15451 (comment), if an external version is explicitly used, the current behavior is preserved and the index is still created and the document is marked for deletion.
Fixes #15425