Skip to content
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

Merged
merged 6 commits into from
Jan 10, 2019

Conversation

jtibshirani
Copy link
Contributor

@jtibshirani jtibshirani commented Jan 8, 2019

This PR adds the REST parameter include_type_name to the following APIs that we originally missed: indices.get_field_mapping, indices.get_template, and indices.put_template. To make sure we're continuously able to run backwards compatibility tests, the parameter is temporarily defaulted to true, but will eventually default to false on 7.0. The detailed steps I plan to take:

  1. Add include_type_name to 7.0, defaulting to true (this PR).
  2. Backport this PR to 6.x, keeping the default true. Make sure to add notes about include_type_name to the REST documentation.
  3. On 7.0, update the default to false and fix up REST tests.

Note that this PR does not add deprecation warnings, or make any changes to the HLRC.

@jtibshirani jtibshirani added WIP :Search Foundations/Mapping Index mappings, including merging and defining field types >deprecation v7.0.0 v6.7.0 labels Jan 8, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

@jtibshirani jtibshirani force-pushed the include-type-name branch 7 times, most recently from f1cc8f1 to 6e1dc33 Compare January 9, 2019 04:51
@jtibshirani jtibshirani removed the WIP label Jan 9, 2019
Copy link
Member

@cbuescher cbuescher left a 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) {
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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 {
Copy link
Member

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"?

Copy link
Contributor Author

@jtibshirani jtibshirani Jan 9, 2019

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.

Copy link
Member

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) {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.");
}
Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@jtibshirani
Copy link
Contributor Author

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 include_type_name (but not add deprecation warnings or touch the Java HLRC classes), to make it available to other teams starting their upgrade. I am quickly doing this first, separately from any deprecations or HLRC work, in order to make the typeless APIs available to other teams as soon as possible. For this reason we don't see some of the usual unit testing around deprecations and xContent parsing.

Copy link
Member

@cbuescher cbuescher left a 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.

jtibshirani added a commit to jtibshirani/elasticsearch that referenced this pull request Jan 11, 2019
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>deprecation :Search Foundations/Mapping Index mappings, including merging and defining field types v6.7.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants