Skip to content

Commit

Permalink
Throw exception on duplicate mappings metadata fields
Browse files Browse the repository at this point in the history
In elastic#57701 we changed mappings merging so that duplicate fields specified in mappings caused an
exception during validation. This change makes the same exception thrown when metadata fields are
duplicated. This will allow us to be strict currently with plans to make the merging more
fine-grained in a later release.
  • Loading branch information
dakrone committed Jun 8, 2020
1 parent eda4da1 commit 7743104
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,7 @@ static Map<String, Map<String, Object>> parseV2Mappings(String mappingsJson, Lis
Map<String, Object> innerTemplateNonProperties = new HashMap<>(innerTemplateMapping);
Map<String, Object> maybeProperties = (Map<String, Object>) innerTemplateNonProperties.remove("properties");

nonProperties = removeDuplicatedDynamicTemplates(nonProperties, innerTemplateNonProperties);
XContentHelper.mergeDefaults(innerTemplateNonProperties, nonProperties);
nonProperties = innerTemplateNonProperties;
nonProperties = mergeFailingOnReplacement(nonProperties, innerTemplateNonProperties);

if (maybeProperties != null) {
properties = mergeFailingOnReplacement(properties, maybeProperties);
Expand All @@ -600,9 +598,7 @@ static Map<String, Map<String, Object>> parseV2Mappings(String mappingsJson, Lis
Map<String, Object> innerRequestNonProperties = new HashMap<>(innerRequestMappings);
Map<String, Object> maybeRequestProperties = (Map<String, Object>) innerRequestNonProperties.remove("properties");

nonProperties = removeDuplicatedDynamicTemplates(nonProperties, innerRequestMappings);
XContentHelper.mergeDefaults(innerRequestNonProperties, nonProperties);
nonProperties = innerRequestNonProperties;
nonProperties = mergeFailingOnReplacement(nonProperties, innerRequestNonProperties);

if (maybeRequestProperties != null) {
properties = mergeFailingOnReplacement(properties, maybeRequestProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,12 +949,11 @@ private static void validateCompositeTemplate(final ClusterState state,
// Parse mappings to ensure they are valid after being composed
List<CompressedXContent> mappings = resolveMappings(stateWithIndex, templateName);
try {
Map<String, Map<String, Object>> finalMappings =
MetadataCreateIndexService.parseV2Mappings("{}", mappings, xContentRegistry);
MapperService dummyMapperService = tempIndexService.mapperService();
for (CompressedXContent mapping : mappings) {
// TODO: Eventually change this to:
// dummyMapperService.merge(MapperService.SINGLE_MAPPING_NAME, mapping, MergeReason.INDEX_TEMPLATE);
dummyMapperService.merge(MapperService.SINGLE_MAPPING_NAME, mapping, MergeReason.MAPPING_UPDATE);
}
// TODO: Eventually change this to use MergeReason.INDEX_TEMPLATE
dummyMapperService.merge(finalMappings, MergeReason.MAPPING_UPDATE);
} catch (Exception e) {
throw new IllegalArgumentException("invalid composite mappings for [" + templateName + "]", e);
}
Expand Down

0 comments on commit 7743104

Please sign in to comment.