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

[Rest Compatible Api] include_type_name parameter #70966

Merged
merged 43 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ddf6152
transformation working
pgomulka Mar 26, 2021
51ef24a
style
pgomulka Mar 29, 2021
1bbc802
test fix
pgomulka Mar 29, 2021
9592c74
is true as a parameter
pgomulka Mar 29, 2021
b6abb3f
create index passing except for get mappings api
pgomulka Mar 29, 2021
4ead400
code style
pgomulka Mar 30, 2021
10dde5e
Merge remote-tracking branch 'upstream/master' into compat/include_ty…
pgomulka Mar 30, 2021
adead4d
test fix
pgomulka Mar 30, 2021
c8f7413
fix test
pgomulka Mar 30, 2021
57e63fc
style check
pgomulka Mar 30, 2021
539b421
add all changes
pgomulka Mar 30, 2021
27c80c0
disable compat xpack tests
pgomulka Mar 31, 2021
2ea3520
Merge remote-tracking branch 'upstream/master' into compat/include_ty…
pgomulka Mar 31, 2021
4c707bb
test
pgomulka Mar 31, 2021
4dcd63c
unit tests
pgomulka Mar 31, 2021
39d7633
Merge remote-tracking branch 'upstream/master' into compat/include_ty…
pgomulka Mar 31, 2021
b384677
enable xpack compat tests
pgomulka Mar 31, 2021
0cc4427
small cleanups
pgomulka Mar 31, 2021
64c7e90
fix test
pgomulka Mar 31, 2021
8da814d
Merge remote-tracking branch 'upstream/master' into compat/include_ty…
pgomulka Apr 1, 2021
734e8b8
add blacklist
pgomulka Apr 2, 2021
276fc88
sort and join
pgomulka Apr 2, 2021
07db905
fix build.gradle
pgomulka Apr 2, 2021
bc0e5df
enable all tests
pgomulka Apr 2, 2021
0835b80
fix block list
pgomulka Apr 2, 2021
22c5175
Merge remote-tracking branch 'upstream/master' into compat/include_ty…
pgomulka Apr 12, 2021
9e1644f
review follow up. remove the type checks in rollover request
pgomulka Apr 12, 2021
2049d0e
bring back a check against type without include_type_name
pgomulka Apr 13, 2021
e7298ee
Merge remote-tracking branch 'upstream/master' into compat/include_ty…
pgomulka Apr 13, 2021
a1ea94c
remove stale gradle transformations
pgomulka Apr 13, 2021
0426b02
Merge remote-tracking branch 'upstream/master' into compat/include_ty…
pgomulka Apr 13, 2021
5f1b950
missing version quard check
pgomulka Apr 14, 2021
95bba64
precommit
pgomulka Apr 15, 2021
176da8d
Merge remote-tracking branch 'upstream/master' into compat/include_ty…
pgomulka Apr 15, 2021
2199c3e
code review follow up
pgomulka Apr 15, 2021
8c57e85
keep the test ignored
pgomulka Apr 15, 2021
53f7556
Merge remote-tracking branch 'upstream/master' into compat/include_ty…
pgomulka Apr 15, 2021
a571491
tweak comment
pgomulka Apr 19, 2021
6a5708a
Merge remote-tracking branch 'upstream/master' into compat/include_ty…
pgomulka Apr 19, 2021
75edcd3
enable some xpack plugin tests
pgomulka Apr 19, 2021
b00c1cb
Merge remote-tracking branch 'upstream/master' into compat/include_ty…
pgomulka Apr 19, 2021
5f2620b
fix xpack-plugin block list
pgomulka Apr 19, 2021
063d043
fix build
pgomulka Apr 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 26 additions & 43 deletions rest-api-spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,9 @@ tasks.named("yamlRestCompatTest").configure {
'explain/21_source_filtering_with_types/Source filtering',
'explain/31_query_string_with_types/explain with query_string parameters',
'explain/40_mix_typeless_typeful/Explain with typeless API on an index that has types',
'field_caps/10_basic/Get date_nanos field caps',
'field_caps/30_filter/Field caps with index filter',
'get/100_mix_typeless_typeful/GET with typeless API on an index that has types',// failing due to include_type_name #48632
'get/21_stored_fields_with_types/Stored fields', // failing due to include_type_name #48632
'get/71_source_filtering_with_types/Source filtering',// failing due to include_type_name #48632
// WILL NOT BE FIXED - failing due to not recognising missing type (the type path param is ignored)
jtibshirani marked this conversation as resolved.
Show resolved Hide resolved
'get/100_mix_typeless_typeful/GET with typeless API on an index that has types',
'get_source/11_basic_with_types/Basic with types',
'get_source/16_default_values_with_types/Default values',
'get_source/41_routing_with_types/Routing',
Expand All @@ -160,43 +158,35 @@ tasks.named("yamlRestCompatTest").configure {
'get_source/81_missing_with_types/Missing document with ignore',
'get_source/86_source_missing_with_types/Missing document source with catch',
'get_source/86_source_missing_with_types/Missing document source with ignore',
'index/70_mix_typeless_typeful/Index call that introduces new field mappings', // failing due to include_type_name #48632
'index/70_mix_typeless_typeful/Index with typeless API on an index that has types', // failing due to include_type_name #48632
'indices.clone/10_basic/Clone index via API',
'indices.create/10_basic/Create index with explicit _doc type',
'indices.create/10_basic/Create index without soft deletes',
'indices.create/11_basic_with_types/Create index',
'indices.create/11_basic_with_types/Create index with aliases',
// 5 below await retrofitting Removes typed URLs from mapping APIs #41676
'indices.create/11_basic_with_types/Create index with mappings',
'indices.create/11_basic_with_types/Create index with settings',
'indices.create/11_basic_with_types/Create index with wait_for_active_shards set to all',
'indices.create/11_basic_with_types/Create index with write aliases',
'indices.create/20_mix_typeless_typeful/Create a typed index while there is a typeless template',
'indices.create/20_mix_typeless_typeful/Create a typeless index while there is a typed template',
'indices.create/20_mix_typeless_typeful/Implicitly create a typed index while there is a typeless template',
'indices.create/20_mix_typeless_typeful/Implicitly create a typeless index while there is a typed template',
//
'indices.flush/10_basic/Flush stats',
'indices.flush/10_basic/Index synced flush rest test',
'indices.forcemerge/10_basic/Check deprecation warning when incompatible only_expunge_deletes and max_num_segments values are both set',
'indices.get/11_basic_with_types/Test include_type_name',
'indices.get/11_basic_with_types/Test include_type_name dafaults to false',
'indices.get_field_mapping/10_basic/Get field mapping with local is deprecated',
'indices.get_field_mapping/11_basic_with_types/Get field mapping by index only',
'indices.get_field_mapping/11_basic_with_types/Get field mapping by type & field',
'indices.get_field_mapping/11_basic_with_types/Get field mapping by type & field, with another field that doesn\'t exist',
'indices.get_field_mapping/11_basic_with_types/Get field mapping should work without index specifying type and fields',
'indices.get_field_mapping/11_basic_with_types/Get field mapping with include_defaults',
'indices.get_field_mapping/11_basic_with_types/Get field mapping with no index and type',
'indices.get_field_mapping/21_missing_field_with_types/Return empty object if field doesn\'t exist, but type and index do',
'indices.get_field_mapping/30_missing_type/Raise 404 when type doesn\'t exist',
'indices.get_field_mapping/51_field_wildcards_with_types/Get field mapping should work using \'*\' for indices and types',
'indices.get_field_mapping/51_field_wildcards_with_types/Get field mapping should work using \'_all\' for indices and types',
'indices.get_field_mapping/51_field_wildcards_with_types/Get field mapping should work using comma_separated values for indices and types',
'indices.get_field_mapping/51_field_wildcards_with_types/Get field mapping with * for fields',
'indices.get_field_mapping/51_field_wildcards_with_types/Get field mapping with *t1 for fields',
'indices.get_field_mapping/51_field_wildcards_with_types/Get field mapping with t* for fields',
'indices.get_field_mapping/51_field_wildcards_with_types/Get field mapping with wildcarded relative names',
'indices.get_field_mapping/60_mix_typeless_typeful/GET mapping with typeless API on an index that has types',
'indices.get_field_mapping/10_basic/Get field mapping with local is deprecated',// awaits #41676
'indices.get_field_mapping/11_basic_with_types/Get field mapping by index only',// awaits #41676
'indices.get_field_mapping/11_basic_with_types/Get field mapping by type & field',// awaits #41676
'indices.get_field_mapping/11_basic_with_types/Get field mapping by type & field, with another field that doesn\'t exist',// awaits #41676
'indices.get_field_mapping/11_basic_with_types/Get field mapping should work without index specifying type and fields',// awaits #41676
'indices.get_field_mapping/11_basic_with_types/Get field mapping with include_defaults',// awaits #41676
'indices.get_field_mapping/11_basic_with_types/Get field mapping with no index and type',// awaits #41676
'indices.get_field_mapping/21_missing_field_with_types/Return empty object if field doesn\'t exist, but type and index do',// awaits #41676
'indices.get_field_mapping/30_missing_type/Raise 404 when type doesn\'t exist',// awaits #41676
'indices.get_field_mapping/51_field_wildcards_with_types/Get field mapping should work using \'*\' for indices and types',// awaits #41676
'indices.get_field_mapping/51_field_wildcards_with_types/Get field mapping should work using \'_all\' for indices and types',// awaits #41676
'indices.get_field_mapping/51_field_wildcards_with_types/Get field mapping should work using comma_separated values for indices and types',// awaits #41676
'indices.get_field_mapping/51_field_wildcards_with_types/Get field mapping with * for fields',// awaits #41676
'indices.get_field_mapping/51_field_wildcards_with_types/Get field mapping with *t1 for fields',// awaits #41676
'indices.get_field_mapping/51_field_wildcards_with_types/Get field mapping with t* for fields',// awaits #41676
'indices.get_field_mapping/51_field_wildcards_with_types/Get field mapping with wildcarded relative names',// awaits #41676
'indices.get_field_mapping/60_mix_typeless_typeful/GET mapping with typeless API on an index that has types',// awaits #41676
'indices.get_mapping/11_basic_with_types/Get /*/_mapping/{type}',
'indices.get_mapping/11_basic_with_types/Get /_all/_mapping/{type}',
'indices.get_mapping/11_basic_with_types/Get /_mapping',
Expand All @@ -217,8 +207,6 @@ tasks.named("yamlRestCompatTest").configure {
'indices.get_mapping/40_aliases/Getting mapping for aliases should return the real index as key',
'indices.get_mapping/61_empty_with_types/Check empty mapping when getting all mappings via /_mapping',
'indices.get_mapping/70_mix_typeless_typeful/GET mapping with typeless API on an index that has types',
'indices.get_template/11_basic_with_types/Get template',
'indices.get_template/11_basic_with_types/Get template with no mappings',
'indices.open/10_basic/?wait_for_active_shards default is deprecated',
'indices.open/10_basic/?wait_for_active_shards=index-setting',
'indices.put_mapping/10_basic/Put mappings with explicit _doc type',
Expand All @@ -233,15 +221,9 @@ tasks.named("yamlRestCompatTest").configure {
'indices.put_mapping/all_path_options_with_types/put mapping in prefix* index',
'indices.put_mapping/all_path_options_with_types/put mapping with blank index',
'indices.put_mapping/all_path_options_with_types/put one mapping per index',
'indices.put_template/10_basic/Put template with explicit _doc type',
'indices.put_template/11_basic_with_types/Put multiple template',
'indices.put_template/11_basic_with_types/Put template',
// there is a small distinction between empty mappings and no mappings at all. The code to implement this test was refactored #54003
// not fixing this in #70966
'indices.put_template/11_basic_with_types/Put template with empty mappings',
'indices.rollover/10_basic/Rollover index via API',
'indices.rollover/20_max_doc_condition/Max docs rollover conditions matches only primary shards',
'indices.rollover/30_max_size_condition/Rollover with max_size condition',
'indices.rollover/40_mapping/Mappings with explicit _doc type',
'indices.rollover/41_mapping_with_types/Typeless mapping',
'indices.segments/10_basic/basic segments test',
'indices.segments/10_basic/closed segments test',
'indices.shard_stores/10_basic/basic index test',
Expand Down Expand Up @@ -302,8 +284,6 @@ tasks.named("yamlRestCompatTest").configure {
'search.aggregation/10_histogram/Deprecated _time order',
'search.aggregation/200_top_hits_metric/top_hits aggregation with sequence numbers',
'search.aggregation/20_terms/Deprecated _term order',
'search.aggregation/280_geohash_grid/Basic test',
'search.aggregation/290_geotile_grid/Basic test',
'search.aggregation/51_filter_with_types/Filter aggs with terms lookup and ensure it\'s cached',
'search.inner_hits/10_basic/Nested doc version and seqIDs',
'search.inner_hits/10_basic/Nested inner hits',
Expand Down Expand Up @@ -363,6 +343,9 @@ tasks.named("transformV7RestTests").configure({ task ->
task.replaceMatch("nodes.\$node_id.roles.8", "ml", "node_info role test")
task.replaceMatch("nodes.\$node_id.roles.9", "remote_cluster_client", "node_info role test")
task.removeMatch("nodes.\$node_id.roles.10", "node_info role test")
task.replaceIsTrue("test_index.mappings.type_1", "test_index.mappings._doc")
task.replaceIsFalse("test_index.mappings.type_1", "test_index.mappings._doc")
task.replaceIsFalse("test-1.mappings.my_type", "test-1.mappings._doc")
})

tasks.register('enforceYamlTestConvention').configure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.MappingMetadata;
import org.elasticsearch.common.RestApiVersion;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.io.stream.StreamInput;
Expand All @@ -26,6 +27,9 @@
import java.util.List;
import java.util.Objects;

import static org.elasticsearch.rest.BaseRestHandler.DEFAULT_INCLUDE_TYPE_NAME_POLICY;
import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER;

/**
* A response for a get index action.
*/
Expand Down Expand Up @@ -192,7 +196,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
if (indexMappings == null) {
builder.startObject("mappings").endObject();
} else {
builder.field("mappings", indexMappings.sourceAsMap());
if (builder.getRestApiVersion() == RestApiVersion.V_7 &&
params.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY)) {
builder.startObject("mappings");
builder.field(MapperService.SINGLE_MAPPING_NAME, indexMappings.sourceAsMap());
builder.endObject();
} else {
builder.field("mappings", indexMappings.sourceAsMap());
}
}

builder.startObject("settings");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.RestApiVersion;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand All @@ -22,6 +23,7 @@
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.rest.BaseRestHandler;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -30,6 +32,7 @@
import java.util.Objects;

import static java.util.Collections.unmodifiableMap;
import static org.elasticsearch.rest.BaseRestHandler.DEFAULT_INCLUDE_TYPE_NAME_POLICY;

/**
* Response object for {@link GetFieldMappingsRequest} API
Expand Down Expand Up @@ -84,15 +87,23 @@ public FieldMappingMetadata fieldMappings(String index, String field) {

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {

builder.startObject();
for (Map.Entry<String, Map<String, FieldMappingMetadata>> indexEntry : mappings.entrySet()) {
builder.startObject(indexEntry.getKey());
builder.startObject(MAPPINGS.getPreferredName());

if (indexEntry.getValue() != null) {
addFieldMappingsToBuilder(builder, params, indexEntry.getValue());
if (builder.getRestApiVersion() == RestApiVersion.V_7 &&
params.paramAsBoolean(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY)) {
builder.startObject(MapperService.SINGLE_MAPPING_NAME);
addFieldMappingsToBuilder(builder, params, indexEntry.getValue());
builder.endObject();
} else {
addFieldMappingsToBuilder(builder, params, indexEntry.getValue());
}
}


builder.endObject();
builder.endObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.RestApiVersion;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.ByteSizeValue;
Expand All @@ -37,7 +38,7 @@
*/
public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implements IndicesRequest {

private static final ObjectParser<RolloverRequest, Void> PARSER = new ObjectParser<>("rollover");
private static final ObjectParser<RolloverRequest, Boolean> PARSER = new ObjectParser<>("rollover");
private static final ObjectParser<Map<String, Condition<?>>, Void> CONDITION_PARSER = new ObjectParser<>("conditions");

private static final ParseField CONDITIONS = new ParseField("conditions");
Expand Down Expand Up @@ -67,14 +68,32 @@ public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implem
CONDITIONS, ObjectParser.ValueType.OBJECT);
PARSER.declareField((parser, request, context) -> request.createIndexRequest.settings(parser.map()),
CreateIndexRequest.SETTINGS, ObjectParser.ValueType.OBJECT);
PARSER.declareField((parser, request, includeTypeName) -> {
if (includeTypeName) {
//expecting one type only
for (Map.Entry<String, Object> mappingsEntry : parser.map().entrySet()) {
request.createIndexRequest.mapping((Map<String, Object>) mappingsEntry.getValue());
}
} else {
// a type is not included, add a dummy _doc type
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than doing a check here I think we should just wrap it with _doc and pass it on. If they haven't included include_type_name then we're in the typeless world and they shouldn't be including types in their mappings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I basically tried to retrofit the change from 7.x branch.
Could a user set include_type_name to false, in this case they are using a compatible only feature - include_type_name field but are not using types in a mapping

Map<String, Object> mappings = parser.map();
if (MapperService.isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, mappings)) {
throw new IllegalArgumentException("The mapping definition cannot be nested under a type " +
"[" + MapperService.SINGLE_MAPPING_NAME + "] unless include_type_name is set to true.");
}
request.createIndexRequest.mapping(mappings);
}
}, CreateIndexRequest.MAPPINGS.forRestApiVersion(RestApiVersion.equalTo(RestApiVersion.V_7)), ObjectParser.ValueType.OBJECT);
PARSER.declareField((parser, request, context) -> {
// a type is not included, add a dummy _doc type
Map<String, Object> mappings = parser.map();
if (MapperService.isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, mappings)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

And I think we should remove this check as well - really to check properly we need to parse the mappings, and if they've included a type this will get caught further along.

Copy link
Contributor

Choose a reason for hiding this comment

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

Building on what I said in a previous comment -- these were added in #38270 to catch an important case that mapping parsing wasn't able to detect. But there have been substantial improvements/ refactors to mapping parsing since then, so we may be able to remove these checks and have the tests still pass. To keep this PR a straightforward 'restore' of old logic, maybe we could look into removing these checks in a follow-up.

Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming I am reading the code correctly, this check is only applied when REST API compatibility for v7 is applied (i.e. CreateIndexRequest.MAPPINGS.forRestApiVersion(RestApiVersion.equalTo(RestApiVersion.V_7)), but the check is now no longer for v8+.

I have a minor preference to keep the check when compatibility is in use, else remove the check in a follow up PR if it also requires changes to the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, in that case I will keep the check for both 7.x and 8.x fields.
@romseygeek any views on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

++ let's keep it for now and I can look at removing it in a followup


throw new IllegalArgumentException("The mapping definition cannot be nested under a type");
}
request.createIndexRequest.mapping(mappings);
}, CreateIndexRequest.MAPPINGS, ObjectParser.ValueType.OBJECT);
}, CreateIndexRequest.MAPPINGS.forRestApiVersion(RestApiVersion.onOrAfter(RestApiVersion.V_8)), ObjectParser.ValueType.OBJECT);

PARSER.declareField((parser, request, context) -> request.createIndexRequest.aliases(parser.map()),
CreateIndexRequest.ALIASES, ObjectParser.ValueType.OBJECT);
}
Expand Down Expand Up @@ -238,7 +257,7 @@ public CreateIndexRequest getCreateIndexRequest() {
}

// param isTypeIncluded decides how mappings should be parsed from XContent
public void fromXContent(XContentParser parser) throws IOException {
PARSER.parse(parser, this, null);
public void fromXContent(boolean isTypeIncluded, XContentParser parser) throws IOException {
PARSER.parse(parser, this, isTypeIncluded);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.common.RestApiVersion;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent;
Expand All @@ -20,6 +21,7 @@
import java.util.Objects;

import static java.util.Collections.singletonMap;
import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER;

public class GetIndexTemplatesResponse extends ActionResponse implements ToXContentObject {

Expand Down Expand Up @@ -65,7 +67,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

builder.startObject();
for (IndexTemplateMetadata indexTemplateMetadata : getIndexTemplates()) {
IndexTemplateMetadata.Builder.toXContent(indexTemplateMetadata, builder, params);
if(builder.getRestApiVersion() == RestApiVersion.V_7 &&
params.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, false)) {
IndexTemplateMetadata.Builder.toXContentWithTypes(indexTemplateMetadata, builder, params);
} else {
IndexTemplateMetadata.Builder.toXContent(indexTemplateMetadata, builder, params);
}
}
builder.endObject();
return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
import java.util.Objects;
import java.util.Set;

import static org.elasticsearch.common.RestApiVersion.V_8;
import static org.elasticsearch.common.RestApiVersion.onOrAfter;


public class IndexTemplateMetadata extends AbstractDiffable<IndexTemplateMetadata> {

private final String name;
Expand Down Expand Up @@ -378,7 +382,9 @@ private static void toInnerXContent(IndexTemplateMetadata indexTemplateMetadata,
indexTemplateMetadata.settings().toXContent(builder, params);
builder.endObject();

includeTypeName &= (params.paramAsBoolean("reduce_mappings", false) == false);
if(builder.getRestApiVersion().matches(onOrAfter(V_8))) {
includeTypeName &= (params.paramAsBoolean("reduce_mappings", false) == false);
}
Copy link
Contributor Author

@pgomulka pgomulka Apr 15, 2021

Choose a reason for hiding this comment

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

@romseygeek do you think there need to be a special handing for this in V7 mode?
The logic for 7.x was more complex, but it feels like it was a behaviour change

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 this reduce_mappings parameter is only set internally, so I don't think we want to put a Rest API version guard on it. It's for things like template upgrades or building internal indexes from templates.


CompressedXContent m = indexTemplateMetadata.mappings();
if (m != null) {
Expand Down
Loading