Skip to content

Commit 5c8232c

Browse files
authored
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.
1 parent 84edf36 commit 5c8232c

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

core/src/main/java/org/elasticsearch/index/mapper/DynamicTemplate.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public static XContentFieldType fromString(String value) {
152152
return v;
153153
}
154154
}
155-
throw new IllegalArgumentException("No xcontent type matched on [" + value + "], possible values are "
155+
throw new IllegalArgumentException("No field type matched on [" + value + "], possible values are "
156156
+ Arrays.toString(values()));
157157
}
158158

@@ -208,6 +208,8 @@ public static DynamicTemplate parse(String name, Map<String, Object> conf,
208208
if (indexVersionCreated.onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) {
209209
throw e;
210210
} else {
211+
DEPRECATION_LOGGER.deprecated("match_mapping_type [" + matchMappingType + "] is invalid and will be ignored: "
212+
+ e.getMessage());
211213
// this template is on an unknown type so it will never match anything
212214
// null indicates that the template should be ignored
213215
return null;

core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplateTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@ public void testParseUnknownMatchType() throws IOException {
5050
templateDef.put("mapping", Collections.singletonMap("store", true));
5151
// if a wrong match type is specified, we ignore the template
5252
assertNull(DynamicTemplate.parse("my_template", templateDef, Version.V_5_0_0_alpha5));
53-
53+
assertWarnings("match_mapping_type [short] is invalid and will be ignored: No field type matched on [short], " +
54+
"possible values are [object, string, long, double, boolean, date, binary]");
5455
Map<String, Object> templateDef2 = new HashMap<>();
5556
templateDef2.put("match_mapping_type", "text");
5657
templateDef2.put("mapping", Collections.singletonMap("store", true));
5758
// if a wrong match type is specified, we ignore the template
5859
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
5960
() -> DynamicTemplate.parse("my_template", templateDef2, Version.V_6_0_0_alpha1_UNRELEASED));
60-
assertEquals("No xcontent type matched on [text], possible values are [object, string, long, double, boolean, date, binary]",
61+
assertEquals("No field type matched on [text], possible values are [object, string, long, double, boolean, date, binary]",
6162
e.getMessage());
6263
}
6364

0 commit comments

Comments
 (0)