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

Remove type parameter from CreateIndexRequest.mapping(type, XContentBuilder) #50586

Merged

Conversation

romseygeek
Copy link
Contributor

This continues the removal of type parameters from CreateIndexRequest.mapping
methods started in #50419. Here the removed methods are almost entirely in test
code, with the exception of a change to TransformIndex in the transform plugin.

Relates to #41059

@romseygeek romseygeek added :Search Foundations/Mapping Index mappings, including merging and defining field types :Distributed/CRUD A catch all label for issues around indexing, updating and getting a doc by id. Not search. >refactoring v8.0.0 labels Jan 3, 2020
@romseygeek romseygeek self-assigned this Jan 3, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Mapping)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (:Distributed/CRUD)

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.

This looks good to me overall, just left a suggestion + some questions.

.startObject()
.startObject("test")
.startObject("_doc")
Copy link
Contributor

Choose a reason for hiding this comment

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

To double-check I understand -- we could already remove the mentions to _doc in mapping definitions, but we'll postpone that for another PR? This approach makes sense to me, as it helps keep the current PR focused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's correct - there's also still a bit of inconsistency as to when things need to be wrapped and when not, which this PR moves us one more step towards resolving.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

* @param source The mapping source
*/
public CreateIndexRequest mapping(String type, XContentBuilder source) {
return mapping(type, BytesReference.bytes(source), source.contentType());
public CreateIndexRequest mapping(XContentBuilder source) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency with the changes in CreateIndexRequestBuilder, it would be great if we also removed the type parameter from public CreateIndexRequest mapping(String type, Map<String, ?> source), and converted as many callers as possible to use the new signature. Here's a suggestion for how to do it:


    public CreateIndexRequest mapping(Map<String, ?> source) {
        return mapping(MapperService.SINGLE_MAPPING_NAME, source);
    }

    private CreateIndexRequest mapping(String type, Map<String, ?> source) {
        // wrap it in a type map if its not
        if (source.size() != 1 || !source.containsKey(type)) {
            source = Map.of(MapperService.SINGLE_MAPPING_NAME, source);
        }
        ...
    }

The private method is still needed to support CreateIndexRequest#source.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

++

@@ -291,7 +283,7 @@ else if (MapperService.SINGLE_MAPPING_NAME.equals(type) == false) {
* ("field1", "type=string,store=true").
*/
public CreateIndexRequest mapping(String type, Object... source) {
mapping(type, PutMappingRequest.buildFromSimplifiedDef(type, source));
mapping(PutMappingRequest.buildFromSimplifiedDef(MapperService.SINGLE_MAPPING_NAME, source));
Copy link
Contributor

Choose a reason for hiding this comment

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

For context, what's the plan to remove these remaining methods that accept Object... source?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My current plan is to have a new method, mappingFromSimplifiedDef(Objects... source), and remove the existing method, to make sure that we get compilation failures rather than silently treating the type parameter as part of the source.

@romseygeek romseygeek merged commit a59b065 into elastic:master Jan 8, 2020
SivagurunathanV pushed a commit to SivagurunathanV/elasticsearch that referenced this pull request Jan 23, 2020
…Builder)` (elastic#50586)

This continues the removal of type parameters from CreateIndexRequest.mapping
methods started in elastic#50419. Here the removed methods are almost entirely in test
code, with the exception of a change to TransformIndex in the transform plugin.

Relates to elastic#41059
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed/CRUD A catch all label for issues around indexing, updating and getting a doc by id. Not search. >refactoring :Search Foundations/Mapping Index mappings, including merging and defining field types v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants