Skip to content

Commit

Permalink
Improve doc parsing errors for badly formed metadata fields (#80696)
Browse files Browse the repository at this point in the history
We currently throw a message that always refers to the `_parent` field,
even though it could be throw from any metadata field, and indeed the
`_parent` field hasn't existed for several versions now.
  • Loading branch information
weizijun authored Nov 15, 2021
1 parent 767a237 commit 3ca033f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private Mapping parse(String type, Map<String, Object> mapping) throws MapperPar
if (typeParser != null) {
iterator.remove();
if (false == fieldNode instanceof Map) {
throw new IllegalArgumentException("[_parent] must be an object containing [type]");
throw new IllegalArgumentException("[" + fieldName + "] config must be an object");
}
@SuppressWarnings("unchecked")
Map<String, Object> fieldNodeMap = (Map<String, Object>) fieldNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,13 @@ public void testMultiFieldsWithFieldAlias() throws IOException {
);
assertEquals("Type [alias] cannot be used in multi field", e.getMessage());
}

public void testBadMetadataMapper() throws IOException {
XContentBuilder builder = topMapping(b -> { b.field(RoutingFieldMapper.NAME, "required"); });
IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> createMappingParser(Settings.EMPTY).parse("_doc", new CompressedXContent(BytesReference.bytes(builder)))
);
assertEquals("[_routing] config must be an object", e.getMessage());
}
}

0 comments on commit 3ca033f

Please sign in to comment.