Skip to content

Commit

Permalink
[Rest Api Compatibility] Do not return _doc for empty mappings in tem…
Browse files Browse the repository at this point in the history
…plate

Previously the compatibility layer was alwayre returning an _doc for get
template.
This commit does not return _doc in mappings when mappings are empty.
Returning just {} empty object

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
  • Loading branch information
pgomulka committed Jul 19, 2021
1 parent e978b72 commit d3325de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 2 additions & 6 deletions rest-api-spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ def v7compatibilityNotSupportedTests = {

'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


'field_caps/30_filter/Field caps with index filter', //behaviour change after #63692 4digits dates are parsed as epoch and in quotes as year

'indices.forcemerge/10_basic/Check deprecation warning when incompatible only_expunge_deletes and max_num_segments values are both set', //#44761 bug fix
]
}
tasks.named("yamlRestCompatTest").configure {
Expand All @@ -91,12 +92,7 @@ tasks.named("yamlRestCompatTest").configure {
'cluster.voting_config_exclusions/10_basic/Throw exception when adding voting config exclusion and specifying both node_ids and node_names',
'cluster.voting_config_exclusions/10_basic/Throw exception when adding voting config exclusion without specifying nodes',
'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',
// not fixing this in #70966
'indices.put_template/11_basic_with_types/Put template with empty mappings',
'search.aggregation/200_top_hits_metric/top_hits aggregation with sequence numbers',
'search.aggregation/51_filter_with_types/Filter aggs with terms lookup and ensure it\'s cached',
'search/150_rewrite_on_coordinator/Ensure that we fetch the document only once', //terms_lookup
'search/310_match_bool_prefix/multi_match multiple fields with cutoff_frequency throws exception', //cutoff_frequency
'search/340_type_query/type query', // type_query - probably should behave like match_all
] + v7compatibilityNotSupportedTests())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.mapper.MapperService;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down Expand Up @@ -391,6 +392,8 @@ private static void toInnerXContent(IndexTemplateMetadata indexTemplateMetadata,
Map<String, Object> documentMapping = XContentHelper.convertToMap(m.uncompressed(), true).v2();
if (includeTypeName == false) {
documentMapping = reduceMapping(documentMapping);
} else {
documentMapping = reduceEmptyMapping(documentMapping);
}
builder.field("mappings");
builder.map(documentMapping);
Expand All @@ -405,6 +408,16 @@ private static void toInnerXContent(IndexTemplateMetadata indexTemplateMetadata,
builder.endObject();
}

@SuppressWarnings("unchecked")
private static Map<String, Object> reduceEmptyMapping(Map<String, Object> mapping) {
if(mapping.keySet().size() == 1 && mapping.containsKey(MapperService.SINGLE_MAPPING_NAME) &&
((Map<String, Object>)mapping.get(MapperService.SINGLE_MAPPING_NAME)).size() == 0){
return (Map<String, Object>) mapping.values().iterator().next();
} else {
return mapping;
}
}

@SuppressWarnings("unchecked")
private static Map<String, Object> reduceMapping(Map<String, Object> mapping) {
assert mapping.keySet().size() == 1 : mapping.keySet();
Expand Down

0 comments on commit d3325de

Please sign in to comment.