|
21 | 21 | import org.elasticsearch.common.settings.Settings; |
22 | 22 | import org.elasticsearch.common.xcontent.XContentHelper; |
23 | 23 | import org.elasticsearch.index.IndexVersion; |
| 24 | +import org.elasticsearch.index.IndexVersions; |
24 | 25 | import org.elasticsearch.plugins.internal.XContentMeteringParserDecorator; |
25 | 26 | import org.elasticsearch.test.XContentTestUtils; |
| 27 | +import org.elasticsearch.test.index.IndexVersionUtils; |
26 | 28 | import org.elasticsearch.xcontent.XContentBuilder; |
27 | 29 | import org.elasticsearch.xcontent.XContentFactory; |
28 | 30 | import org.elasticsearch.xcontent.XContentParser; |
@@ -1376,6 +1378,42 @@ public void testSubobjectsFalseWithInnerNestedFromDynamicTemplate() { |
1376 | 1378 | ); |
1377 | 1379 | } |
1378 | 1380 |
|
| 1381 | + /** |
| 1382 | + * test that bad mapping is accepted for indices created before 8.0.0. |
| 1383 | + * We still need to test this in v9 because of N-2 read compatibility |
| 1384 | + */ |
| 1385 | + public void testMalformedDynamicMapping_v7() throws IOException { |
| 1386 | + String mapping = """ |
| 1387 | + { |
| 1388 | + "_doc": { |
| 1389 | + "dynamic_templates": [ |
| 1390 | + { |
| 1391 | + "my_template": { |
| 1392 | + "mapping": { |
| 1393 | + "ignore_malformed": true, |
| 1394 | + "type": "keyword" |
| 1395 | + }, |
| 1396 | + "path_match": "*" |
| 1397 | + } |
| 1398 | + } |
| 1399 | + ] |
| 1400 | + } |
| 1401 | + } |
| 1402 | + """; |
| 1403 | + MapperParsingException ex = expectThrows(MapperParsingException.class, () -> createMapperService(mapping)); |
| 1404 | + assertThat(ex.getMessage(), containsString("dynamic template [my_template] has invalid content")); |
| 1405 | + |
| 1406 | + // the previous exception should be ignored by indices with v7 index versions |
| 1407 | + IndexVersion indexVersion = IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.V_8_0_0); |
| 1408 | + Settings settings = Settings.builder().put("number_of_shards", 1).put("index.version.created", indexVersion).build(); |
| 1409 | + MapperService mapperService = createMapperService(indexVersion, settings, () -> randomBoolean()); |
| 1410 | + merge(mapperService, mapping); |
| 1411 | + assertWarnings( |
| 1412 | + "Parameter [ignore_malformed] is used in a dynamic template mapping and has no effect on type [keyword]. " |
| 1413 | + + "Usage will result in an error in future major versions and should be removed." |
| 1414 | + ); |
| 1415 | + } |
| 1416 | + |
1379 | 1417 | public void testSubobjectsAutoFlatPaths() throws IOException { |
1380 | 1418 | assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled()); |
1381 | 1419 | MapperService mapperService = createDynamicTemplateAutoSubobjects(); |
|
0 commit comments