From 5c8232c03b8c7c0edbea74d8139f441083a6d439 Mon Sep 17 00:00:00 2001 From: Luca Cavanna Date: Wed, 21 Dec 2016 16:56:55 +0100 Subject: [PATCH] Restore deprecation warning for invalid match_mapping_type values (#22304) The deprecation warning gives now the same message as 5.x. The deprecation warning was previously removed, but given that we are still lenient with old indices we should still output the warning. --- .../java/org/elasticsearch/index/mapper/DynamicTemplate.java | 4 +++- .../org/elasticsearch/index/mapper/DynamicTemplateTests.java | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/mapper/DynamicTemplate.java b/core/src/main/java/org/elasticsearch/index/mapper/DynamicTemplate.java index dcb991095b2..c31306c7fa3 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/DynamicTemplate.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/DynamicTemplate.java @@ -152,7 +152,7 @@ public class DynamicTemplate implements ToXContent { return v; } } - throw new IllegalArgumentException("No xcontent type matched on [" + value + "], possible values are " + throw new IllegalArgumentException("No field type matched on [" + value + "], possible values are " + Arrays.toString(values())); } @@ -208,6 +208,8 @@ public class DynamicTemplate implements ToXContent { if (indexVersionCreated.onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { throw e; } else { + DEPRECATION_LOGGER.deprecated("match_mapping_type [" + matchMappingType + "] is invalid and will be ignored: " + + e.getMessage()); // this template is on an unknown type so it will never match anything // null indicates that the template should be ignored return null; diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplateTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplateTests.java index 24023281f5e..42dd8c3bf37 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplateTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplateTests.java @@ -50,14 +50,15 @@ public class DynamicTemplateTests extends ESTestCase { templateDef.put("mapping", Collections.singletonMap("store", true)); // if a wrong match type is specified, we ignore the template assertNull(DynamicTemplate.parse("my_template", templateDef, Version.V_5_0_0_alpha5)); - + assertWarnings("match_mapping_type [short] is invalid and will be ignored: No field type matched on [short], " + + "possible values are [object, string, long, double, boolean, date, binary]"); Map 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]", + assertEquals("No field type matched on [text], possible values are [object, string, long, double, boolean, date, binary]", e.getMessage()); }