-
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
Types removal - deprecate types in _bulk apis #36549
Conversation
Pinging @elastic/es-search |
ea45401
to
e339b40
Compare
a940e53
to
177e75a
Compare
run gradle build tests |
1 similar comment
run gradle build tests |
f578b66
to
c0e198f
Compare
run gradle build tests |
1 similar comment
run gradle build tests |
c36372f
to
c0b5dea
Compare
46ceae8
to
e3233f3
Compare
d69dec4
to
49b3568
Compare
The last remaining test failure is a rolling upgrade test (IndexingIT) which looks to be failing when a 6.x node is given a types removal warning by a 7.x node. |
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 a huge effort!! I left a few preliminary comments as I got up to speed with the approach.
} | ||
} | ||
{ | ||
//Check that untyped document additions and untyped global inherit the established custom type |
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.
Would you be able to explain a bit what 'inherit the custom type' means here? I'm a little unclear on why the custom type would be relevant, since we're setting both the global and local types to null
.
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.
It means the custom document type introduced to the mapping by the earlier code in this test. I'll add a comment.
@@ -55,7 +55,7 @@ public void testReindex() throws IOException { | |||
RestStatus.OK, | |||
highLevelClient().bulk( | |||
bulkRequest, | |||
RequestOptions.DEFAULT | |||
expectWarnings(BulkRequest.TYPES_DEPRECATION_MESSAGE) |
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 that since the reindex PR (#36823) was merged, this is no longer necessary.
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.
Yep, in fact this false expectation causes an error. Will fix
@@ -686,7 +686,7 @@ public void testBulk() throws Exception { | |||
.source(XContentType.JSON,"field", "baz")); | |||
// end::bulk-request | |||
// tag::bulk-execute | |||
BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); | |||
BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); |
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.
Small comment -- some trailing whitespace here.
@@ -103,7 +103,7 @@ public void setUpDocs() throws IOException { | |||
.endObject()); | |||
bulkRequest.add(indexRequest); | |||
} | |||
BulkResponse bulkResponse = highLevelClient().bulk(bulkRequest, RequestOptions.DEFAULT); | |||
BulkResponse bulkResponse = highLevelClient().bulk(bulkRequest, expectWarnings(BulkRequest.TYPES_DEPRECATION_MESSAGE)); |
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.
Would it be possible to modify the bulk call instead of expecting a warning here?
@@ -495,6 +496,9 @@ public void testRollover() throws IOException { | |||
Request bulkRequest = new Request("POST", "/" + index + "_write/doc/_bulk"); | |||
bulkRequest.setJsonEntity(bulk.toString()); | |||
bulkRequest.addParameter("refresh", ""); | |||
bulkRequest.setOptions(expectVersionSpecificWarnings((v)->{ |
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 can just be expectWarnings
(same as the call below).
@@ -76,6 +80,8 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC | |||
String defaultType = request.param("type"); | |||
if (defaultType == null) { | |||
defaultType = MapperService.SINGLE_MAPPING_NAME; | |||
} else { | |||
deprecationLogger.deprecatedAndMaybeLog("bulk_with_types", BulkRequest.TYPES_DEPRECATION_MESSAGE); |
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.
Small comment: would it make sense to move the deprecation message to this action class, for consistency with the other APIs?
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.
If that's the convention, sure, I can make that change
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.
👍
9609212
to
a448066
Compare
run gradle build tests |
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.
This is looking good to me! I will wait on the build results before hitting 'approve', in case another issue comes up or you'd like another pair of eyes on it (some of the changes around defaults in IndexRequest
are a bit subtle).
|
||
private BulkResponse bulkWithTypes(BulkRequest request) throws IOException { | ||
BulkResponse bulkResponse = execute(request, highLevelClient()::bulk, highLevelClient()::bulkAsync, | ||
expectVersionSpecificWarnings((v)->{v.current(BulkRequest.TYPES_DEPRECATION_MESSAGE);})); |
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.
One more instance of expectVersionSpecificWarnings
that can be updated to expectWarnings
.
@@ -1070,6 +1072,9 @@ private void checkSnapshot(String snapshotName, int count, Version tookOnVersion | |||
Request writeToRestoredRequest = new Request("POST", "/restored_" + index + "/doc/_bulk"); | |||
writeToRestoredRequest.addParameter("refresh", "true"); | |||
writeToRestoredRequest.setJsonEntity(bulk.toString()); | |||
writeToRestoredRequest.setOptions(expectVersionSpecificWarnings((v)->{ |
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 thought here.
@@ -82,7 +83,7 @@ | |||
*/ | |||
static final int MAX_SOURCE_LENGTH_IN_TOSTRING = 2048; | |||
|
|||
private String type = MapperService.SINGLE_MAPPING_NAME; | |||
private String type; |
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.
It might be useful to add a comment to these files IndexRequest
, UpdateRequest
, and DeleteRequest
) explaining the different states of the type parameter, as it is not very obvious to a newcomer. I really should've done this in my initial PRs that began to modify these files, apologies for punting on that.
@elasticmachine run gradle build tests 1 |
21d2f8d
to
32a917a
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.
Thanks @markharwood, this looks good to me. My only other thought is that it'd be good to update the PR description with an explanation of how bulk, index, update, and delete requests have changed (perhaps mentioning defaultTypeIfNull
).
@@ -51,7 +51,7 @@ public void testBulkPipelineUpsert() throws Exception { | |||
new RestBulkAction(settings(Version.CURRENT).build(), mock(RestController.class)) |
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.
In other PRs we have added a dedicated test here to ensure we're emitting deprecation warnings. However, there are several integration tests in this PR that maked typed calls and check for deprecation warnings, so I don't think it's strictly necessary.
2955a7f
to
4bea050
Compare
run gradle build tests |
f0d8a00
to
c2a16b7
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.
@markharwood I did a first quick pass ignoring the changes in test classes, will take a look at those also if needed
/** | ||
* @deprecated Types are in the process of being removed. Use {@link #BulkRequest(String)} instead | ||
*/ | ||
@Deprecated | ||
public BulkRequest(@Nullable String globalIndex, @Nullable String globalType) { |
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.
It looks like CRUDDocumentationIT is using this deprecatd ctor still (amongst other). Since its code that is contained in the docs, should we move that to using the typeless constructor?
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 not sure - it's documentation showing how index
and type
can be associated with the BulkRequest and "inherited" by an IndexRequest objects that are missing these values.
I suppose it's a general point if we want documentation to include supported-yet-deprecated features? I can pull the docs/code if we think that's the right thing. Thoughts? cc @jtibshirani
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.
We've been removing documentation for deprecated features, with the understanding that users can refer to the previous version's documentation (where the feature is not deprecated).
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.
Thanks for the clarification, I think you are refering to https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-high-document-bulk.html#CO102-1. I would be in favour of removing the mentioning of the type there as well and changing to the other ctor then.
* or empty | ||
* @return the Request | ||
*/ | ||
T defaultTypeIfNull(String defaultType); |
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 briefly explain why this is added? Only to improve my understanding of the PR.
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.
Bulk requests can specify a default index and type which is automatically filled-in on any contained Index/Update/DeleteRequests that are missing these properties. A form of inheritance.
This is the method where any blank choice of type is overridden with the BulkRequest's choice of type. This code became necessary after a different PR switched the Index/Update/DeleteRequests to default to _doc
instead of null - all the bulk type inheritance tests failed because we couldn't differentiate between objects where the user had explicitly defined a choice of _doc
and those where the user had not made an explicit choice. Here we have to revert back to holding a null for this setting by default.
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.
Thanks for the explanation, think I got it.
server/src/main/java/org/elasticsearch/action/bulk/BulkRequestBuilder.java
Show resolved
Hide resolved
@@ -152,9 +154,6 @@ public IndexRequest(String index, String type, String id) { | |||
@Override | |||
public ActionRequestValidationException validate() { | |||
ActionRequestValidationException validationException = super.validate(); | |||
if (type == null) { | |||
validationException = addValidationError("type is missing", validationException); | |||
} |
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.
Any reason this is removed here but still validated in DeleteRequest?
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.
No, I can't think why they should differ
@markharwood rest of the PR (test changes) look good to me btw. |
facae87
to
89aa779
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.
@markharwood thanks for the update, LGTM.
4ee1cf8
to
0f17436
Compare
Added warnings checks to existing tests Added “defaultTypeIfNull” to DocWriteRequest interface so that Bulk requests can override a null choice of document type with any global custom choice.
0f17436
to
82e72df
Compare
Some remaining work (e.g.
CRUDDocumentationIT.testBulk
code examples) depends on @mayya-sharipova 's changes toIndexRequest
for the singular index apis.