Support empty properties array in mappings

closes #5887
This commit is contained in:
Shay Banon 2014-05-01 12:18:39 -04:00
parent 42a112f50b
commit a557ee8daf
2 changed files with 16 additions and 1 deletions

View File

@ -28,6 +28,7 @@ import org.apache.lucene.queries.TermFilter;
import org.apache.lucene.search.Filter; import org.apache.lucene.search.Filter;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchIllegalStateException; import org.elasticsearch.ElasticsearchIllegalStateException;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.joda.FormatDateTimeFormatter;
@ -214,7 +215,13 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll {
} else if (fieldName.equals("path")) { } else if (fieldName.equals("path")) {
builder.pathType(parsePathType(name, fieldNode.toString())); builder.pathType(parsePathType(name, fieldNode.toString()));
} else if (fieldName.equals("properties")) { } else if (fieldName.equals("properties")) {
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<String, Object>) fieldNode, parserContext); parseProperties(builder, (Map<String, Object>) fieldNode, parserContext);
}
} else if (fieldName.equals("include_in_all")) { } else if (fieldName.equals("include_in_all")) {
builder.includeInAll(nodeBooleanValue(fieldNode)); builder.includeInAll(nodeBooleanValue(fieldNode));
} else { } else {

View File

@ -56,4 +56,12 @@ public class SimpleObjectMappingTests extends ElasticsearchTestCase {
// all is well // 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);
}
} }