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

Allow indices.get_mapping response parsing without types #37492

Merged
merged 5 commits into from
Jan 18, 2019

Conversation

cbuescher
Copy link
Member

This change adds deprecation warning to the indices.get_mapping API in case the
"inlcude_type_name" parameter is set to "true" and changes the parsing code in
GetMappingsResponse to parse the type-less response instead of the one
containing types. As a consequence the HLRC client doesn't need to force
"include_type_name=true" any more and the GetMappingsResponseTests can be
adapted to the new format as well. Also removing some "include_type_name"
parameters in yaml test and docs where not necessary.

This change adds deprecation warning to the indices.get_mapping API in case the
"inlcude_type_name" parameter is set to "true" and changes the parsing code in
GetMappingsResponse to parse the type-less response instead of the one
containing types. As a consequence the HLRC client doesn't need to force
"include_type_name=true" any more and the GetMappingsResponseTests can be
adapted to the new format as well. Also removing some "include_type_name"
parameters in yaml test and docs where not necessary.
@cbuescher cbuescher added >feature :Search Foundations/Mapping Index mappings, including merging and defining field types v7.0.0 >refactoring labels Jan 15, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

Copy link
Contributor

@jtibshirani jtibshirani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few small comments, but this is looking good overall!

@@ -13,20 +13,7 @@ setup:
mappings:
doc: {}
---
"Get /{index}/_mapping with empty mappings":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why these tests were removed, plus the ones in 61_empty_with_types?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I think I missread this test as already being covered by the general setup, buts its checking that the "mappings" key exists even if no field mapping is there at all. Will revert.
About 61_empty_with_types: I think the behaviour of the test and the assertions shouldn't differ from 60_empy.yml at all if used with "include_type_name" or not. In fact I think we can remove the "skip" section from "60_empty" which is what I will do and see if it passes the mixed cluster tests.

Copy link
Contributor

@jtibshirani jtibshirani Jan 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mean to belabor this too much, but I think the point of the tests was to check that we return the correct response for empty mappings in both the cases where include_type_name=false, and include_type_name=true, as these are two separate codepaths. Just removing the skip section from 60_empty won't test the include_type_name=true case on 7.0.

It also seems nice to stick with the guidelines laid out in #37285 (comment), so it's easier to understand what's going on in all the tests. In particular, if the test explicitly tests typeless APIs on 7.0 then we've been omitting include_type_name, but for mixed-version tests, we explicitly set include_type_name=false.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining, that makes sense to me now, will revert "61_empty_with_types"

.build();

RestGetMappingAction handler = new RestGetMappingAction(Settings.EMPTY, mock(RestController.class));
handler.prepareRequest(request, mock(NodeClient.class));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could just do controller().dispatchRequest here, as we do in the test above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work without some more involved mocking which I think isn't necessary here. If using the "standard" approach from other tests I get a NPE in org.elasticsearch.rest.action.admin.indices.RestGetMappingAction.lambda$0(RestGetMappingAction.java:105 because the client isn't fully mocked out. I'd rather keep it this way, it tests what it is supposed to test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if (fieldMappings.isEmpty() == false) {
assert fieldMappings instanceof Map : "expected a map as inner type mapping, but got: " + fieldMappings.getClass();
MappingMetaData mmd = new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, fieldMappings);
typeBuilder.put(MapperService.SINGLE_MAPPING_NAME, mmd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming that we'll revisit the interface to GetMappingsResponse for the HLRC, as we plan to do for GetIndexResponse.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say so, as I'm still not conviced we if/how we should do this just now, so I'd like to discuss this more focussed in a separate move.

@cbuescher
Copy link
Member Author

@elasticmachine run the gradle build tests 1
@elasticmachine run the gradle build tests 2

@cbuescher
Copy link
Member Author

@elasticmachine run the gradle build tests 1

@@ -59,6 +60,8 @@
public class RestGetMappingAction extends BaseRestHandler {
private static final Logger logger = LogManager.getLogger(RestGetMappingAction.class);
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(logger);
static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using `include_type_name` in get mapping requests is deprecated. "
+ "The parameter will be removed in the next major version.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #37484 I opted for a general "include_type_name is deprecated" message as that is our system-wide policy. I'm not sure if it's more useful to warn people they shouldn't be using the param anywhere or that it was detected in use on a particular API as in this case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I like that the deprecation explicitely says which API call this warning comes from. You might be able to see the same from the logger, but then again maybe not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been taking the same approach as @cbuescher, so it is really clear what API call is causing the warning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last (small) comment I thought of -- we should probably standardize on using `include_type_name` (with backticks) vs. include_type_name in these messages, for easy searchability. I think I would vote for no backticks, since I don't see them used often in our logging messages?

@cbuescher
Copy link
Member Author

@elasticmachine run the gradle build tests 1

1 similar comment
@cbuescher
Copy link
Member Author

@elasticmachine run the gradle build tests 1

@cbuescher
Copy link
Member Author

@elasticmachine run the gradle build tests 1
@elasticmachine run the gradle build tests 2

@cbuescher
Copy link
Member Author

@elasticmachine run the gradle build tests 2

4 similar comments
@cbuescher
Copy link
Member Author

@elasticmachine run the gradle build tests 2

@cbuescher
Copy link
Member Author

@elasticmachine run the gradle build tests 2

@cbuescher
Copy link
Member Author

@elasticmachine run the gradle build tests 2

@cbuescher
Copy link
Member Author

@elasticmachine run the gradle build tests 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>feature >refactoring :Search Foundations/Mapping Index mappings, including merging and defining field types v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants