Throw an exception on unrecognized "match_mapping_type"

When using dynamic templates, ES will now throw an exception if a
`match_mapping_type` is used that doesn't correspond to an actual type.

Relates to #17285
This commit is contained in:
Lee Hinman 2016-12-09 14:36:45 -07:00
parent b667ff46c4
commit a4e8b5d952
4 changed files with 26 additions and 8 deletions

View File

@ -205,15 +205,13 @@ public class DynamicTemplate implements ToXContent {
try { try {
xcontentFieldType = XContentFieldType.fromString(matchMappingType); xcontentFieldType = XContentFieldType.fromString(matchMappingType);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// TODO: do this in 6.0 if (indexVersionCreated.onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) {
/*if (indexVersionCreated.onOrAfter(Version.V_6_0_0)) {
throw e; throw e;
}*/ } else {
// this template is on an unknown type so it will never match anything
DEPRECATION_LOGGER.deprecated("Ignoring unrecognized match_mapping_type: [" + matchMappingType + "]"); // null indicates that the template should be ignored
// this template is on an unknown type so it will never match anything return null;
// null indicates that the template should be ignored }
return null;
} }
} }
return new DynamicTemplate(name, pathMatch, pathUnmatch, match, unmatch, xcontentFieldType, MatchType.fromString(matchPattern), mapping); return new DynamicTemplate(name, pathMatch, pathUnmatch, match, unmatch, xcontentFieldType, MatchType.fromString(matchPattern), mapping);

View File

@ -49,6 +49,15 @@ public class DynamicTemplateTests extends ESTestCase {
templateDef.put("mapping", Collections.singletonMap("store", true)); templateDef.put("mapping", Collections.singletonMap("store", true));
// if a wrong match type is specified, we ignore the template // if a wrong match type is specified, we ignore the template
assertNull(DynamicTemplate.parse("my_template", templateDef, Version.V_5_0_0_alpha5)); assertNull(DynamicTemplate.parse("my_template", templateDef, Version.V_5_0_0_alpha5));
Map<String, Object> templateDef2 = new HashMap<>();
templateDef2.put("match_mapping_type", "text");
templateDef2.put("mapping", Collections.singletonMap("store", true));
// if a wrong match type is specified, we ignore the template
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> DynamicTemplate.parse("my_template", templateDef2, Version.V_6_0_0_alpha1_UNRELEASED));
assertEquals("No xcontent type matched on [text], possible values are [object, string, long, double, boolean, date, binary]",
e.getMessage());
} }
public void testMatchAllTemplate() { public void testMatchAllTemplate() {

View File

@ -28,6 +28,7 @@ way to reindex old indices is to use the `reindex` API.
* <<breaking_60_stats_changes>> * <<breaking_60_stats_changes>>
* <<breaking_60_rest_changes>> * <<breaking_60_rest_changes>>
* <<breaking_60_search_changes>> * <<breaking_60_search_changes>>
* <<breaking_60_mappings_changes>>
* <<breaking_60_docs_changes>> * <<breaking_60_docs_changes>>
* <<breaking_60_cluster_changes>> * <<breaking_60_cluster_changes>>
* <<breaking_60_settings_changes>> * <<breaking_60_settings_changes>>
@ -43,6 +44,8 @@ include::migrate_6_0/rest.asciidoc[]
include::migrate_6_0/search.asciidoc[] include::migrate_6_0/search.asciidoc[]
include::migrate_6_0/mappings.asciidoc[]
include::migrate_6_0/docs.asciidoc[] include::migrate_6_0/docs.asciidoc[]
include::migrate_6_0/cluster.asciidoc[] include::migrate_6_0/cluster.asciidoc[]

View File

@ -0,0 +1,8 @@
[[breaking_60_mappings_changes]]
=== Mapping changes
==== Unrecognized `match_mapping_type` options not silently ignored
Previously Elastiscearch would silently ignore any dynamic templates that
included a `match_mapping_type` type that was unrecognized. An exception is now
thrown on an unrecognized type.