|
|
@@ -125,6 +125,35 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|
|
e.getMessage());
|
|
|
}
|
|
|
|
|
|
+ public void testUnexpectedFieldMappingType() throws Exception {
|
|
|
+ DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
|
|
|
+ String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
|
|
|
+ .startObject("foo").field("type", "long").endObject()
|
|
|
+ .startObject("bar").field("type", "boolean").endObject()
|
|
|
+ .startObject("geo").field("type", "geo_shape").endObject()
|
|
|
+ .endObject().endObject().endObject());
|
|
|
+ DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping));
|
|
|
+ {
|
|
|
+ BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("foo", true).endObject());
|
|
|
+ MapperException exception = expectThrows(MapperException.class,
|
|
|
+ () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
|
|
|
+ assertThat(exception.getMessage(), containsString("failed to parse field [foo] of type [long]"));
|
|
|
+ }
|
|
|
+ {
|
|
|
+ BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("bar", "bar").endObject());
|
|
|
+ MapperException exception = expectThrows(MapperException.class,
|
|
|
+ () -> mapper.parse(SourceToParse.source("test", "type", "2", bytes, XContentType.JSON)));
|
|
|
+ assertThat(exception.getMessage(), containsString("failed to parse field [bar] of type [boolean]"));
|
|
|
+ }
|
|
|
+ {
|
|
|
+ BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("geo", 123).endObject());
|
|
|
+ MapperException exception = expectThrows(MapperException.class,
|
|
|
+ () -> mapper.parse(SourceToParse.source("test", "type", "2", bytes, XContentType.JSON)));
|
|
|
+ assertThat(exception.getMessage(), containsString("failed to parse field [geo] of type [geo_shape]"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public void testDotsWithDynamicNestedMapper() throws Exception {
|
|
|
DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
|
|
|
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
|