Merge pull request #17768 from rjernst/dots4

Mappings: Fix array parsing to remove its context when finished parsing
This commit is contained in:
Ryan Ernst 2016-04-15 00:22:55 -07:00
commit c3f4eb36e3
2 changed files with 23 additions and 0 deletions

View File

@ -88,6 +88,10 @@ final class DocumentParser {
parser.close();
}
}
String remainingPath = context.path().pathAsText("");
if (remainingPath.isEmpty() == false) {
throw new IllegalStateException("found leftover path elements: " + remainingPath);
}
reverseOrder(context);
@ -542,6 +546,7 @@ final class DocumentParser {
context.addDynamicMapper(mapper);
context.path().add(arrayFieldName);
parseObjectOrField(context, mapper);
context.path().remove();
} else {
parseNonDynamicArray(context, parentMapper, lastFieldName, arrayFieldName);
}

View File

@ -178,4 +178,22 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
assertTrue(barMapper instanceof ObjectMapper);
assertNotNull(((ObjectMapper)barMapper).getMapper("baz"));
}
public void testDynamicArrayWithTemplate() throws Exception {
DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startArray("dynamic_templates").startObject().startObject("georule")
.field("match", "foo*")
.startObject("mapping").field("type", "geo_point").endObject()
.endObject().endObject().endArray().endObject().endObject().string();
DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping));
BytesReference bytes = XContentFactory.jsonBuilder()
.startObject().startArray("foo")
.startArray().value(0).value(0).endArray()
.startArray().value(1).value(1).endArray()
.endArray().endObject().bytes();
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
assertEquals(2, doc.rootDoc().getFields("foo").length);
}
}