mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-09 14:34:43 +00:00
Merge pull request #17768 from rjernst/dots4
Mappings: Fix array parsing to remove its context when finished parsing
This commit is contained in:
commit
c3f4eb36e3
@ -88,6 +88,10 @@ final class DocumentParser {
|
|||||||
parser.close();
|
parser.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String remainingPath = context.path().pathAsText("");
|
||||||
|
if (remainingPath.isEmpty() == false) {
|
||||||
|
throw new IllegalStateException("found leftover path elements: " + remainingPath);
|
||||||
|
}
|
||||||
|
|
||||||
reverseOrder(context);
|
reverseOrder(context);
|
||||||
|
|
||||||
@ -542,6 +546,7 @@ final class DocumentParser {
|
|||||||
context.addDynamicMapper(mapper);
|
context.addDynamicMapper(mapper);
|
||||||
context.path().add(arrayFieldName);
|
context.path().add(arrayFieldName);
|
||||||
parseObjectOrField(context, mapper);
|
parseObjectOrField(context, mapper);
|
||||||
|
context.path().remove();
|
||||||
} else {
|
} else {
|
||||||
parseNonDynamicArray(context, parentMapper, lastFieldName, arrayFieldName);
|
parseNonDynamicArray(context, parentMapper, lastFieldName, arrayFieldName);
|
||||||
}
|
}
|
||||||
|
@ -178,4 +178,22 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||||||
assertTrue(barMapper instanceof ObjectMapper);
|
assertTrue(barMapper instanceof ObjectMapper);
|
||||||
assertNotNull(((ObjectMapper)barMapper).getMapper("baz"));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user