Skip to content

Commit cfbc1f7

Browse files
add and fix yaml tests
1 parent d6a49b3 commit cfbc1f7

File tree

4 files changed

+56
-12
lines changed

4 files changed

+56
-12
lines changed

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/10_basic.yml

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,59 @@
217217
---
218218
"Create index with invalid field type":
219219
- requires:
220-
cluster_features: ["gte_v8.19.0"]
221-
reason: "The error message updated after 8.18"
220+
cluster_features: [ "mapper.unknown_field_mapping_update_error_message" ]
221+
reason: "Update error message for unknown field type"
222+
222223
- do:
224+
catch: /bad_request/
223225
indices.create:
224226
index: test_index
225227
body:
226228
mappings:
227229
properties:
228-
"content":
230+
content:
231+
type: invalid
232+
233+
- match: { error.type: "mapper_parsing_exception" }
234+
- match: { error.reason: "The mapper type [invalid] declared on field [content] does not exist. It might have been created within a future version or requires a plugin to be installed. Check the documentation." }
235+
236+
---
237+
"Create index with invalid runtime field type":
238+
- requires:
239+
cluster_features: [ "mapper.unknown_field_mapping_update_error_message" ]
240+
reason: "Update error message for unknown field type"
241+
242+
- do:
243+
catch: /bad_request/
244+
indices.create:
245+
index: test_index
246+
body:
247+
mappings:
248+
runtime:
249+
content:
229250
type: invalid
230251

231252
- match: { error.type: "mapper_parsing_exception" }
232-
- match: { error.reason: "The mapper type [invalid] does not exist. It might have been created within a future version or requires a plugin to be installed. Check the documentation." }
253+
- match: { error.reason: "The mapper type [invalid] declared on field [content] does not exist. It might have been created within a future version or requires a plugin to be installed. Check the documentation." }
233254

255+
---
256+
"Create index with invalid multi-field type":
257+
- requires:
258+
cluster_features: [ "mapper.unknown_field_mapping_update_error_message" ]
259+
reason: "Update error message for unknown field type"
260+
261+
- do:
262+
catch: /bad_request/
263+
indices.create:
264+
index: test_index
265+
body:
266+
mappings:
267+
properties:
268+
city:
269+
type: text
270+
fields:
271+
raw:
272+
type: invalid
273+
274+
- match: { error.type: "mapper_parsing_exception" }
275+
- match: { error.reason: "The mapper type [invalid] declared on field [city] does not exist. It might have been created within a future version or requires a plugin to be installed. Check the documentation." }

server/src/main/java/org/elasticsearch/index/mapper/MapperFeatures.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public Set<NodeFeature> getTestFeatures() {
5454
TSDB_NESTED_FIELD_SUPPORT,
5555
SourceFieldMapper.SYNTHETIC_RECOVERY_SOURCE,
5656
ObjectMapper.SUBOBJECTS_FALSE_MAPPING_UPDATE_FIX,
57+
ObjectMapper.UKNOWN_FIELD_MAPPING_UPDATE_ERROR_MESSAGE,
5758
DOC_VALUES_SKIPPER
5859
);
5960
}

server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class ObjectMapper extends Mapper {
5050
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(ObjectMapper.class);
5151
public static final FeatureFlag SUB_OBJECTS_AUTO_FEATURE_FLAG = new FeatureFlag("sub_objects_auto");
5252
static final NodeFeature SUBOBJECTS_FALSE_MAPPING_UPDATE_FIX = new NodeFeature("mapper.subobjects_false_mapping_update_fix");
53+
static final NodeFeature UKNOWN_FIELD_MAPPING_UPDATE_ERROR_MESSAGE = new NodeFeature("mapper.unknown_field_mapping_update_error_message");
5354

5455
public static final String CONTENT_TYPE = "object";
5556
static final String STORE_ARRAY_SOURCE_PARAM = "store_array_source";
@@ -397,11 +398,9 @@ protected static void parseProperties(Builder objBuilder, Map<String, Object> pr
397398
Mapper.TypeParser typeParser = parserContext.typeParser(type);
398399
if (typeParser == null) {
399400
throw new MapperParsingException(
400-
"The mapper type ["
401-
+ type
402-
+ "] does not exist."
403-
+ " It might have been created within a future version or requires a plugin to be installed."
404-
+ " Check the documentation."
401+
"The mapper type [" + type + "] declared on field [" + fieldName + "] does not exist."
402+
+ " It might have been created within a future version or requires a plugin to be installed."
403+
+ " Check the documentation."
405404
);
406405
}
407406
Mapper.Builder fieldBuilder;

server/src/test/java/org/elasticsearch/index/mapper/RootObjectMapperTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,16 +313,18 @@ public void testRuntimeSectionMerge() throws IOException {
313313
public void testRuntimeSectionNonRuntimeType() throws IOException {
314314
XContentBuilder mapping = runtimeFieldMapping(builder -> builder.field("type", "unknown"));
315315
MapperParsingException e = expectThrows(MapperParsingException.class, () -> createMapperService(mapping));
316-
assertEquals("Failed to parse mapping: The mapper type [unknown] declared on field [field] does not exist."
317-
+ " It might have been created within a future version or requires a plugin to be installed. Check the documentation.",
316+
assertEquals(
317+
"Failed to parse mapping: The mapper type [unknown] declared on field [field] does not exist."
318+
+ " It might have been created within a future version or requires a plugin to be installed. Check the documentation.",
318319
e.getMessage()
319320
);
320321
}
321322

322323
public void testRuntimeSectionHandlerNotFound() throws IOException {
323324
XContentBuilder mapping = runtimeFieldMapping(builder -> builder.field("type", "unknown"));
324325
MapperParsingException e = expectThrows(MapperParsingException.class, () -> createMapperService(mapping));
325-
assertEquals("Failed to parse mapping: The mapper type [unknown] declared on field [field] does not exist."
326+
assertEquals(
327+
"Failed to parse mapping: The mapper type [unknown] declared on field [field] does not exist."
326328
+ " It might have been created within a future version or requires a plugin to be installed. Check the documentation.",
327329
e.getMessage()
328330
);

0 commit comments

Comments
 (0)