Added Put Mapping API to high-level Rest client (#27205)#27869
Added Put Mapping API to high-level Rest client (#27205)#27869javanna merged 10 commits intoelastic:masterfrom
Conversation
|
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
| } | ||
|
|
||
| static Request putMapping(PutMappingRequest putMappingRequest) throws IOException { | ||
| String endpoint = endpoint(putMappingRequest.indices(), "_mapping", putMappingRequest.type()); |
There was a problem hiding this comment.
Do we want to support putMappingRequest.getConcreteIndex() here? If so, how/when should it be used? Does it make sense to support in client-specific code?
There was a problem hiding this comment.
no that's an internal concept leaked to our external API. Maybe check in RestHighLevelClient that concreteIndex is not set, as it will be ignored.
| } | ||
|
|
||
| /** | ||
| * Creates an index using the Put Mapping API |
There was a problem hiding this comment.
put mapping adds a type or fields to an existing index?
|
IMO this is one of the API we should not add to the REST Client. See discussion at #15613 (comment). If we merge it, we should may be merge it as But I'd prefer that others comment as well. |
|
Fwiw, would it not be simplest to merge this as is, and modify it together with the corresponding endpoint (be it |
|
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
javanna
left a comment
There was a problem hiding this comment.
this looks pretty good @catalin-ursachi thanks a lot! Besides the few comments that I left, I think this only needs docs. If you could work on that, I would be happy to merge this in. Sorry it took me a while to look at it.
| } | ||
|
|
||
| static Request putMapping(PutMappingRequest putMappingRequest) throws IOException { | ||
| String endpoint = endpoint(putMappingRequest.indices(), "_mapping", putMappingRequest.type()); |
There was a problem hiding this comment.
no that's an internal concept leaked to our external API. Maybe check in RestHighLevelClient that concreteIndex is not set, as it will be ignored.
| if (source != null) { | ||
| builder.rawValue(new BytesArray(source), XContentType.JSON); | ||
| } else { | ||
| builder.startObject().endObject(); |
There was a problem hiding this comment.
is it ok here to only end the object? should we not start it too? and above, does rawValue print out a valid complete object?
There was a problem hiding this comment.
I don't understand the first question; we are both starting and ending it, aren't we?
And yes, as source has to be a complete object, rawValue applied by itself to the builder also produces one.
| mapping.endObject(); | ||
| mapping.endObject(); | ||
| mapping.endObject(); | ||
| request.source(mapping); |
There was a problem hiding this comment.
do we need to test the case where source is not set?
| return request; | ||
| } | ||
|
|
||
| private static XContentBuilder randomMapping() throws IOException { |
There was a problem hiding this comment.
@javanna - These two methods are duplicated in CreateIndexRequestTests; what would be a sensible place to commonise them?
There was a problem hiding this comment.
(Although fwiw randomMapping does differ slightly between the two classes)
There was a problem hiding this comment.
you can make one of them public and call it from both tests, I don't mind
There was a problem hiding this comment.
thanks for the update @catalin-ursachi I added a few more comments, nothing major though, and thanks a lot for adding the docs. Once you address my latest comments this should be ready to be merged.
|
|
||
| static Request putMapping(PutMappingRequest putMappingRequest) throws IOException { | ||
| // The concreteIndex is an internal concept, not applicable to requests made over the REST API. | ||
| assert (putMappingRequest.getConcreteIndex() == null); |
There was a problem hiding this comment.
given that a request is provided by users, this should rather be an exception that gets thrown. Also this assertion may make the user's application crash. Throw IllegalArgumentException instead?
| Params parameters = Params.builder(); | ||
| parameters.withTimeout(putMappingRequest.timeout()); | ||
| parameters.withMasterTimeout(putMappingRequest.masterNodeTimeout()); | ||
| parameters.withUpdateAllTypes(putMappingRequest.updateAllTypes()); |
There was a problem hiding this comment.
this parameter has been removed from master, I think that you may see that once you merge master in. I need to remember to add it back though when backporting to 6.x.
| PutMappingRequest putMappingRequest = new PutMappingRequest(indexName); | ||
|
|
||
| putMappingRequest.type("type_name"); | ||
|
|
There was a problem hiding this comment.
nit: can you remove this empty line and the one above please?
| assertTrue(putMappingResponse.isAcknowledged()); | ||
|
|
||
| Map<String, Object> indexMetaData = getIndexMetadata(indexName); | ||
|
|
There was a problem hiding this comment.
nit: can you remove this empty line?
| " }\n" + | ||
| " }\n" + | ||
| " }\n" + | ||
| "}", // <2> |
There was a problem hiding this comment.
was this required? Maybe you can revert this small part?
There was a problem hiding this comment.
The IDE indented the lines; will revert.
Would you like me to add the two extra spaces per line within the string back in? They seemed superfluous.
|
|
||
| String expectedRequestBody = "{}"; | ||
|
|
||
| assertEquals(expectedRequestBody, actualRequestBody); |
There was a problem hiding this comment.
here too can you remove some of these empty lines please?
| return request; | ||
| } | ||
|
|
||
| private static XContentBuilder randomMapping() throws IOException { |
There was a problem hiding this comment.
you can make one of them public and call it from both tests, I don't mind
| mapping.endObject(); | ||
| mapping.endObject(); | ||
| mapping.endObject(); | ||
| request.source(mapping); |
There was a problem hiding this comment.
I had left a comment on this, do we need to test also the case where the source is not set hence it's null? We do cover it in PutMappingRequest#toXContent
There was a problem hiding this comment.
Oh, that's the new testToXContentWithEmptySource below.
(Sorry, all comments got hidden because the merge with master moved all these files to server/...)
| -------------------------------------------------- | ||
| include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-request-source] | ||
| -------------------------------------------------- | ||
| <1> The mapping source |
There was a problem hiding this comment.
should we cover the different way to provide the source like we did in other docs pages (e.g. search API)? I see that we didn't do it for the create index API, but maybe we should have. Shall we have a common page on how to provide a source and link to it? What do you think? Maybe we could also do it as a followup so this PR doesn't get too big.
There was a problem hiding this comment.
That does make sense; but it does rather seem like there could be some more user-friendly mapping-building tools, abstracting out the boilerplate. E.g. the ones in Elastic4s:
createIndex("artists").mappings(
mapping("modern").fields(
textField("name")
)
)
There was a problem hiding this comment.
But anyway; as things are now, I think a separate doc makes sense, so as not to clutter the Create Index and Put Mapping pages too much?
There was a problem hiding this comment.
I agree that we should do better, but for now we are only porting what the transport client supports to the new client. I think that having a separate page would be good so we don't repeat the same content in different pages, I assume that the content would be the same, it can probably already be extracted from the search docs page.
There was a problem hiding this comment.
Cool; I am tempted to suggest doing it as a follow-up PR, then, since I'm not sure I've got the time to do it just now. If you think it's a blocker for this one, though, then that's fair enough.
There was a problem hiding this comment.
agreed, fine as a follow-up PR
There was a problem hiding this comment.
@catalin-ursachi let me know if you want to take this, otherwise I can take care of it.
There was a problem hiding this comment.
By all means feel free to take it; otherwise I'll pick it up when I next set aside some time for OS work, but I can't promise when that is. 🙂
| <2> The type to create (or update) | ||
|
|
||
| ==== Mapping source | ||
| A description of the fields to create on the mapping; if not defined, the mapping will default to empty. |
There was a problem hiding this comment.
should we list this under the optional arguments? After all it is optional?
There was a problem hiding this comment.
Hmm. Technically it's optional; but a PutMapping request without a source just adds a new type; which, in the ES 6.x+ world, is basically meaningless.
|
Made all the requested changes, save for the two outstanding questions. |
|
thanks @catalin-ursachi ! |
…t mapping API Relates to #27869
* es/master: Remove redundant argument for buildConfiguration of s3 plugin (#28281) Completely remove Painless Type from AnalyzerCaster in favor of Java Class. (#28329) Fix spelling error Reindex: Wait for deletion in test Reindex: log more on rare test failure Ensure we protect Collections obtained from scripts from self-referencing (#28335) [Docs] Fix asciidoc style in composite agg docs Adds the ability to specify a format on composite date_histogram source (#28310) Provide a better error message for the case when all shards failed (#28333) [Test] Re-Add integer_range and date_range field types for query builder tests (#28171) Added Put Mapping API to high-level Rest client (#27869) Revert change that does not return all indices if a specific alias is requested via get alias api. (#28294) Painless: Replace Painless Type with Java Class during Casts (#27847) Notify affixMap settings when any under the registered prefix matches (#28317)
* es/6.x: Remove redundant argument for buildConfiguration of s3 plugin (#28281) Completely remove Painless Type from AnalyzerCaster in favor of Java Class. (#28329) Fix spelling error Reindex: Wait for deletion in test Reindex: log more on rare test failure Ensure we protect Collections obtained from scripts from self-referencing (#28335) Provide a better error message for the case when all shards failed (#28333) REST high-level client: add support for update_all_types option to put mapping API Added Put Mapping API to high-level Rest client (#27869) [Test] Re-Add integer_range and date_range field types for query builder tests (#28171) Revert change that does not return all indices if a specific alias is requested via get alias api. (#28294) Painless: Replace Painless Type with Java Class during Casts (#27847) Notify affixMap settings when any under the registered prefix matches (#28317)
* master: (94 commits) Completely remove Painless Type from AnalyzerCaster in favor of Java Class. (elastic#28329) Fix spelling error Reindex: Wait for deletion in test Reindex: log more on rare test failure Ensure we protect Collections obtained from scripts from self-referencing (elastic#28335) [Docs] Fix asciidoc style in composite agg docs Adds the ability to specify a format on composite date_histogram source (elastic#28310) Provide a better error message for the case when all shards failed (elastic#28333) [Test] Re-Add integer_range and date_range field types for query builder tests (elastic#28171) Added Put Mapping API to high-level Rest client (elastic#27869) Revert change that does not return all indices if a specific alias is requested via get alias api. (elastic#28294) Painless: Replace Painless Type with Java Class during Casts (elastic#27847) Notify affixMap settings when any under the registered prefix matches (elastic#28317) Trim down usages of `ShardOperationFailedException` interface (elastic#28312) Do not return all indices if a specific alias is requested via get aliases api. [Test] Lower bwc version for rank-eval rest tests CountedBitSet doesn't need to extend BitSet. (elastic#28239) Calculate sum in Kahan summation algorithm in aggregations (elastic#27807) (elastic#27848) Remove the `update_all_types` option. (elastic#28288) Add information when master node left to DiscoveryNodes' shortSummary() (elastic#28197) ...
|
The preliminary doc https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.x/java-rest-high-put-mapping.html shows how to use putMapping. When attempted on 6.1.2, the api is missing; documentation to set mappings seems incomplete. |
|
Documentation on CreateIndexRequest -- a class in the codebase for 6.1.3 says to fire that request to make a CreateIndexResponse with client.indices().create(...) and, of course, that API is missing. There must be a way to create index/mappings pairs well documented somewhere online. |
|
@KnowledgeGarden to know when something was/will be released, you can check the labels of the PR. This one is marked 6.3.0, meaning that it will be released with 6.3.0. It is true that the request is already there, as it is part of the transport client, but the high-level REST client doesn't support it yet in version 6.1.3. |
|
@javanna Thanks! Timeline for release of 6.3.0? |
|
Hi @KnowledgeGarden; you can of course use the low-level rest client for creating an index and adding a mapping: |
Adds the Put Mapping API (part of #27205).
Still have to write the docs.