diff --git a/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java b/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java index ddeb282647e..1ce367c79e9 100644 --- a/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java @@ -28,6 +28,7 @@ import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.Filter; import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticsearchIllegalStateException; +import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.joda.FormatDateTimeFormatter; @@ -214,7 +215,13 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll { } else if (fieldName.equals("path")) { builder.pathType(parsePathType(name, fieldNode.toString())); } else if (fieldName.equals("properties")) { - parseProperties(builder, (Map) fieldNode, parserContext); + if (fieldNode instanceof Collection && ((Collection) fieldNode).isEmpty()) { + // nothing to do here, empty (to support "properties: []" case) + } else if (!(fieldNode instanceof Map)) { + throw new ElasticsearchParseException("properties must be a map type"); + } else { + parseProperties(builder, (Map) fieldNode, parserContext); + } } else if (fieldName.equals("include_in_all")) { builder.includeInAll(nodeBooleanValue(fieldNode)); } else { diff --git a/src/test/java/org/elasticsearch/index/mapper/object/SimpleObjectMappingTests.java b/src/test/java/org/elasticsearch/index/mapper/object/SimpleObjectMappingTests.java index b94a30c1155..15bd33dd472 100644 --- a/src/test/java/org/elasticsearch/index/mapper/object/SimpleObjectMappingTests.java +++ b/src/test/java/org/elasticsearch/index/mapper/object/SimpleObjectMappingTests.java @@ -56,4 +56,12 @@ public class SimpleObjectMappingTests extends ElasticsearchTestCase { // all is well } } + + @Test + public void testEmptyArrayProperties() throws Exception { + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") + .startArray("properties").endArray() + .endObject().endObject().string(); + MapperTestUtils.newParser().parse(mapping); + } }