-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Allow indices.get_mapping response parsing without types #37492
Conversation
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.
Pinging @elastic/es-search |
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 left a few small comments, but this is looking good overall!
@@ -13,20 +13,7 @@ setup: | |||
mappings: | |||
doc: {} | |||
--- | |||
"Get /{index}/_mapping with empty mappings": |
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 wondering why these tests were removed, plus the ones in 61_empty_with_types
?
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.
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.
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 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
.
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 explaining, that makes sense to me now, will revert "61_empty_with_types"
server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingActionTests.java
Outdated
Show resolved
Hide resolved
.build(); | ||
|
||
RestGetMappingAction handler = new RestGetMappingAction(Settings.EMPTY, mock(RestController.class)); | ||
handler.prepareRequest(request, mock(NodeClient.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.
I think we could just do controller().dispatchRequest
here, as we do in the test above.
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 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.
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.
👍
...c/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java
Outdated
Show resolved
Hide resolved
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); |
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 assuming that we'll revisit the interface to GetMappingsResponse
for the HLRC, as we plan to do for GetIndexResponse
.
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 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.
0f9add6
to
d127196
Compare
@elasticmachine run the gradle build tests 1 |
@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."; |
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 #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.
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 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.
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've been taking the same approach as @cbuescher, so it is really clear what API call is causing the warning.
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 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?
@elasticmachine run the gradle build tests 1 |
1 similar comment
@elasticmachine run the gradle build tests 1 |
@elasticmachine run the gradle build tests 1 |
@elasticmachine run the gradle build tests 2 |
4 similar comments
@elasticmachine run the gradle build tests 2 |
@elasticmachine run the gradle build tests 2 |
@elasticmachine run the gradle build tests 2 |
@elasticmachine run the gradle build tests 2 |
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.