Skip to content

Commit 5485d3e

Browse files
authored
[Rest Api Compatibility] Do not return _doc for empty mappings in template (elastic#75448)
Previously the compatibility layer was always returning an _doc in mappings for get template. This commit does not return _doc in empty mappings. Returning just {} empty object (v7 and v8 behaviour) also moving term lookups tests which are already fixed (relates elastic#74544) relates elastic#70966 relates main meta issue elastic#51816 relates types removal meta elastic#54160
1 parent e978b72 commit 5485d3e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

rest-api-spec/build.gradle

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ def v7compatibilityNotSupportedTests = {
7878

7979
'indices.create/10_basic/Create index without soft deletes', //Make soft-deletes mandatory in 8.0 #51122 - settings changes are note supported in Rest Api compatibility
8080

81-
8281
'field_caps/30_filter/Field caps with index filter', //behaviour change after #63692 4digits dates are parsed as epoch and in quotes as year
82+
83+
'indices.forcemerge/10_basic/Check deprecation warning when incompatible only_expunge_deletes and max_num_segments values are both set', //#44761 bug fix
8384
]
8485
}
8586
tasks.named("yamlRestCompatTest").configure {
@@ -91,12 +92,7 @@ tasks.named("yamlRestCompatTest").configure {
9192
'cluster.voting_config_exclusions/10_basic/Throw exception when adding voting config exclusion and specifying both node_ids and node_names',
9293
'cluster.voting_config_exclusions/10_basic/Throw exception when adding voting config exclusion without specifying nodes',
9394
'indices.flush/10_basic/Index synced flush rest test',
94-
'indices.forcemerge/10_basic/Check deprecation warning when incompatible only_expunge_deletes and max_num_segments values are both set',
95-
// not fixing this in #70966
96-
'indices.put_template/11_basic_with_types/Put template with empty mappings',
9795
'search.aggregation/200_top_hits_metric/top_hits aggregation with sequence numbers',
98-
'search.aggregation/51_filter_with_types/Filter aggs with terms lookup and ensure it\'s cached',
99-
'search/150_rewrite_on_coordinator/Ensure that we fetch the document only once', //terms_lookup
10096
'search/310_match_bool_prefix/multi_match multiple fields with cutoff_frequency throws exception', //cutoff_frequency
10197
'search/340_type_query/type query', // type_query - probably should behave like match_all
10298
] + v7compatibilityNotSupportedTests())

server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetadata.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.elasticsearch.common.xcontent.XContentHelper;
2828
import org.elasticsearch.common.xcontent.XContentParser;
2929
import org.elasticsearch.common.xcontent.json.JsonXContent;
30+
import org.elasticsearch.index.mapper.MapperService;
3031

3132
import java.io.IOException;
3233
import java.io.UncheckedIOException;
@@ -391,6 +392,8 @@ private static void toInnerXContent(IndexTemplateMetadata indexTemplateMetadata,
391392
Map<String, Object> documentMapping = XContentHelper.convertToMap(m.uncompressed(), true).v2();
392393
if (includeTypeName == false) {
393394
documentMapping = reduceMapping(documentMapping);
395+
} else {
396+
documentMapping = reduceEmptyMapping(documentMapping);
394397
}
395398
builder.field("mappings");
396399
builder.map(documentMapping);
@@ -405,6 +408,16 @@ private static void toInnerXContent(IndexTemplateMetadata indexTemplateMetadata,
405408
builder.endObject();
406409
}
407410

411+
@SuppressWarnings("unchecked")
412+
private static Map<String, Object> reduceEmptyMapping(Map<String, Object> mapping) {
413+
if(mapping.keySet().size() == 1 && mapping.containsKey(MapperService.SINGLE_MAPPING_NAME) &&
414+
((Map<String, Object>)mapping.get(MapperService.SINGLE_MAPPING_NAME)).size() == 0){
415+
return (Map<String, Object>) mapping.values().iterator().next();
416+
} else {
417+
return mapping;
418+
}
419+
}
420+
408421
@SuppressWarnings("unchecked")
409422
private static Map<String, Object> reduceMapping(Map<String, Object> mapping) {
410423
assert mapping.keySet().size() == 1 : mapping.keySet();

0 commit comments

Comments
 (0)