Nested Mapping: Nested object with a null value causes wrong indexing structure (resulting in wrong search responses), closes #1323.
This commit is contained in:
parent
8fe1e5cdb8
commit
93b1759804
|
@ -385,6 +385,13 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll {
|
|||
}
|
||||
XContentParser parser = context.parser();
|
||||
|
||||
String currentFieldName = parser.currentName();
|
||||
XContentParser.Token token = parser.currentToken();
|
||||
if (token == XContentParser.Token.VALUE_NULL) {
|
||||
// the object is null ("obj1" : null), simply bail
|
||||
return;
|
||||
}
|
||||
|
||||
Document restoreDoc = null;
|
||||
if (nested.isNested()) {
|
||||
Document nestedDoc = new Document();
|
||||
|
@ -412,12 +419,6 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll {
|
|||
ContentPath.Type origPathType = context.path().pathType();
|
||||
context.path().pathType(pathType);
|
||||
|
||||
String currentFieldName = parser.currentName();
|
||||
XContentParser.Token token = parser.currentToken();
|
||||
if (token == XContentParser.Token.VALUE_NULL) {
|
||||
// the object is null ("obj1" : null), simply bail
|
||||
return;
|
||||
}
|
||||
// if we are at the end of the previous object, advance
|
||||
if (token == XContentParser.Token.END_OBJECT) {
|
||||
token = parser.nextToken();
|
||||
|
|
|
@ -33,6 +33,32 @@ import static org.hamcrest.Matchers.*;
|
|||
@Test
|
||||
public class NestedMappingTests {
|
||||
|
||||
@Test public void emptyNested() throws Exception {
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
|
||||
.startObject("nested1").field("type", "nested").endObject()
|
||||
.endObject().endObject().endObject().string();
|
||||
|
||||
DocumentMapper docMapper = MapperTests.newParser().parse(mapping);
|
||||
|
||||
ParsedDocument doc = docMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "value")
|
||||
.nullField("nested1")
|
||||
.endObject()
|
||||
.copiedBytes());
|
||||
|
||||
assertThat(doc.docs().size(), equalTo(1));
|
||||
|
||||
doc = docMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "value")
|
||||
.startArray("nested").endArray()
|
||||
.endObject()
|
||||
.copiedBytes());
|
||||
|
||||
assertThat(doc.docs().size(), equalTo(1));
|
||||
}
|
||||
|
||||
@Test public void singleNested() throws Exception {
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
|
||||
.startObject("nested1").field("type", "nested").endObject()
|
||||
|
|
Loading…
Reference in New Issue