Add get mappings support to high-level rest client#30889
Add get mappings support to high-level rest client#30889dakrone merged 14 commits intoelastic:masterfrom
Conversation
This adds support for the get mappings API to the high level rest client. Relates to elastic#27205
|
Pinging @elastic/es-core-infra |
javanna
left a comment
There was a problem hiding this comment.
I left a few minor comments, LGTM otherwise
| "_mapping", getMappingsRequest.types())); | ||
|
|
||
| Params parameters = new Params(request); | ||
| parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout()); |
There was a problem hiding this comment.
I don't see this being set in the corresponding REST action, would you mind opening another PR to fix that? It needs to be added to the SPEC too.
|
|
||
| Params parameters = new Params(request); | ||
| parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout()); | ||
| parameters.withIndicesOptions(getMappingsRequest.indicesOptions()); |
There was a problem hiding this comment.
I think that we need to set the local flag also
|
|
||
| static Request getMappings(GetMappingsRequest getMappingsRequest) throws IOException { | ||
| Request request = new Request(HttpGet.METHOD_NAME, endpoint(getMappingsRequest.indices(), | ||
| "_mapping", getMappingsRequest.types())); |
There was a problem hiding this comment.
I think that you need to protect both indices and types from NPEs. Unfortunately you can set null from their setter methods. We already do this for other API.
| getMappingRequest.indices(indices); | ||
|
|
||
| String type = randomAlphaOfLengthBetween(3, 10); | ||
| getMappingRequest.types(type); |
There was a problem hiding this comment.
test setting indices and/or types null also
There was a problem hiding this comment.
can we also test with no types provided?
| Map<String, String> expectedParams = new HashMap<>(); | ||
|
|
||
| setRandomIndicesOptions(getMappingRequest::indicesOptions, getMappingRequest::indicesOptions, expectedParams); | ||
| setRandomMasterTimeout(getMappingRequest, expectedParams); |
There was a problem hiding this comment.
add a test around the local flag?
| return this.mappings.equals(other.mappings); | ||
| } | ||
|
|
||
| private static final class Fields { |
There was a problem hiding this comment.
can we get rid of this inner class and declare the field at the top-level?
| final GetMappingsRequest getMappingsRequest = new GetMappingsRequest(); | ||
| getMappingsRequest.indices(indices).types(types); | ||
| getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions())); | ||
| getMappingsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getMappingsRequest.masterNodeTimeout())); |
There was a problem hiding this comment.
oh thanks I hadn't noticed that you already added this missing line ++ can you double check the spec too?
| message = String.format(Locale.ROOT, "types [%s] missing", toNamesString(difference.toArray(new String[0]))); | ||
| } | ||
| final String message = String.format(Locale.ROOT, "type" + (difference.size() == 1 ? "" : "s") + | ||
| " [%s] missing", Strings.collectionToCommaDelimitedString(difference)); |
There was a problem hiding this comment.
remove the toNamesString method if we no longer use it?
| @@ -129,47 +131,15 @@ public RestResponse buildResponse(final GetMappingsResponse response, final XCon | |||
| status = RestStatus.OK; | |||
| } else { | |||
| status = RestStatus.NOT_FOUND; | |||
There was a problem hiding this comment.
what do think about moving all this logic to the corresponding transport action (as a follow-up)? I didn't look too close but I think that this causes different behaviour between REST and transport at the moment, it would be nice to have a simpler REST action maybe.
There was a problem hiding this comment.
Yeah, I don't love this logic but this isn't the place to remove it, I think it'd be fine as a follow-up. The difficulty is that we are not consistent here (see: #30768 (comment) ) I think we need to sort that out before removing this.
There was a problem hiding this comment.
I am not talking about removing this (I agree it's not nice and we should talk about that), but rather moving this logic to the transport action. That would maintain the same behaviour at REST and most likely change it for transport client users. Anyway, doesn't belong here.
| @@ -83,6 +84,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC | |||
| final GetMappingsRequest getMappingsRequest = new GetMappingsRequest(); | |||
There was a problem hiding this comment.
we may also want to look at removing RestGetAllMappingsAction if possible. As a follow-up.
There was a problem hiding this comment.
Yes, definitely +1 on removing that if possible.
|
Thanks for taking a look @javanna, I think I've addressed all of your comments |
| -------------------------------------------------- | ||
| <1> Returning all indices' mappings | ||
| <2> Retrieving the mappings for a particular index and type | ||
| <3> Getting the mappings for the "tweet" as a Java Map |
There was a problem hiding this comment.
I get these errors when building the docs:
asciidoc: WARNING: get_mappings.asciidoc: line 14: list item index: expected 2 got 1
asciidoc: WARNING: get_mappings.asciidoc: line 15: list item index: expected 3 got 2
There was a problem hiding this comment.
I have no idea why these occur, I checked and there are 3 annotations in IndicesClientDocumentationIT for this tag, and 3 here, not sure why they are off-by-one
|
Thanks for taking a look @javanna |
|
@dakrone do you plan on backporting this as well? |
This adds support for the get mappings API to the high level rest client. Relates to #27205
* elastic/6.x: [Rollup] Disallow index patterns that match the rollup index (#30491) Revert "Fixing MixedClusterClientYamlTestSuiteIT" Fixing MixedClusterClientYamlTestSuiteIT Add get mappings support to high-level rest client (#30889) [DOCS] Fixes security example (#31082) Allow terms query in _rollup_search (#30973)
| include::indices/force_merge.asciidoc[] | ||
| include::indices/rollover.asciidoc[] | ||
| include::indices/put_mapping.asciidoc[] | ||
| include::indices/get_mappings.asciidoc[] |
There was a problem hiding this comment.
heya @dakrone this is not enough for the page to be linked, in fact this API is currently missing in our docs, would you mind fixing that please?
This commit adds the high-level rest client docs for the get mappings API that was added in elastic#30889
This commit adds the high-level rest client docs for the get mappings API that was added in #30889
This commit adds the high-level rest client docs for the get mappings API that was added in #30889
This adds support for the get mappings API to the high level rest client.
Relates to #27205