-
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
Support include_type_name in the field mapping and index template APIs. #37210
Conversation
Pinging @elastic/es-search |
f1cc8f1
to
6e1dc33
Compare
6e1dc33
to
3763ecc
Compare
3763ecc
to
8bbda23
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.
@jtibshirani thanks, I did a first round of reviews, mostly about tests I think that would be good to be added.
One general question: there is no deprecation logging in the various RestHandlers where the "include_type_name" parameter is added now. Is the plan to add those in a later PR or don't we want to add that at all (like we did for other case). From the overview issue (#35190) I was under the impression we want to warn if the parameter is set to indicate that users should remove it and accept the default. Is this missing here because you are not using the intended default or "false" on 7.0 yet?
builder.startObject(fieldEntry.getKey()); | ||
fieldEntry.getValue().toXContent(builder, params); | ||
|
||
if (includeTypeName == false) { |
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 test for the new XContent output case (I think thats includeTypeName=false) to GetFieldMappingsResponseTests please?
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 was hoping to do this when we update GetFieldMappingsResponse#fromXContent
(in a future PR targeting the HLRC), since this test class is based on AbstractStreamableXContentTestCase
which relies on both those methods for xContent testing. For now the toXContent
logic is covered by the indices.get_field_mapping
REST tests. Does that seem reasonable to you?
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.
Sure, covering xContent output in REST tests is fine for now, I'd just like to make sure we have both a roundtrip test (xContent/parsing) for the matching methods plus another unit test for the deprecated output also as a unit test later on. I think having unit tests for even this kind of simple things is important, REST tests are harder to run, maintain and debug which is why for easily testable things like xContent output I'd like to have unit tests in place. But sure this can be done in a follow up.
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.
👍 sounds good, I also much prefer unit tests where possible.
if (mappings != null) { | ||
addFieldMappingsToBuilder(builder, params, mappings); | ||
} | ||
} else { |
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.
Which output is currently compatible with the parsing code in this class? I assume the "old" response output since I don't see changes to the parser. Will that be adapted once you switch the flags default to "false"?
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.
Right, only the 'old' response format is compatible. And yes, the parsing code will be adapted in a follow-up PR that also updates and tests the Java HLRC.
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.
Okay, good to know.
mapping = (Map<String, Object>) mapping.get(cursor.key); | ||
// The parameter include_type_name is only ever used in the REST API, where reduce_mappings is | ||
// always set to true. We therefore only check for include_type_name in this branch. | ||
if (includeTypeName == false) { |
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.
Again, please add at least one test case for the new output to the unit test.
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 as above: I was planning to do this when we update GetIndexTemplatesResponse.fromXContent
in a future PR. This xContent generation is covered for now by the REST tests in indices.get_template
.
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.
sure
if (includeTypeName == false && types.length > 0) { | ||
throw new IllegalArgumentException("Cannot set include_type_name=false and specify" + | ||
" types at the same time."); | ||
} |
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 this be unit tested as well please? I saw no RestGetFieldMappingActionTest though, maybe we should create one.
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.
👍 will add a test for this.
newSourceAsMap.put("mappings", Collections.singletonMap(MapperService.SINGLE_MAPPING_NAME, sourceAsMap.get("mappings"))); | ||
sourceAsMap = newSourceAsMap; | ||
} | ||
putRequest.source(sourceAsMap); |
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 would be nice if we could unit-test this output as well, wlthough I see this might be a bit tricky with the way this is generated here. Maybe generating the response map can be done in a package private helper that can be tested individually?
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 added a unit test for this as well. Just to note, it is also covered by the REST tests under indices.put_template/10_basic
.
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 adding a unit test, same comment as above, I think its great this is covered by REST tests but I prefer unit tests if possible.
Thanks @cbuescher for the review! It might be helpful to think of this PR as having the same format as #29453, but filling in the APIs it missed. It just aims to add the REST flag |
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.
@jtibshirani thanks for the clarifications on my questions and adding the unit test. LGTM from my end.
…s. (elastic#37210) * Add include_type_name to the get field mappings API. * Add include_type_name to the get index templates API. * Add include_type_name to the put index templates API.
This PR adds the REST parameter
include_type_name
to the following APIs that we originally missed:indices.get_field_mapping
,indices.get_template
, andindices.put_template
. To make sure we're continuously able to run backwards compatibility tests, the parameter is temporarily defaulted totrue
, but will eventually default tofalse
on 7.0. The detailed steps I plan to take:include_type_name
to 7.0, defaulting totrue
(this PR).true
. Make sure to add notes aboutinclude_type_name
to the REST documentation.false
and fix up REST tests.Note that this PR does not add deprecation warnings, or make any changes to the HLRC.