|
@@ -110,4 +110,35 @@ public class DocCountFieldMapperTests extends MetadataMapperTestCase {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ public void testSyntheticSourceManyDoNotHave() throws IOException {
|
|
|
+ MapperService mapper = createMapperService(syntheticSourceMapping(b -> b.startObject("doc").field("type", "integer").endObject()));
|
|
|
+ List<Integer> counts = randomList(2, 10000, () -> randomBoolean() ? null : between(1, Integer.MAX_VALUE));
|
|
|
+ withLuceneIndex(mapper, iw -> {
|
|
|
+ int d = 0;
|
|
|
+ for (Integer c : counts) {
|
|
|
+ int doc = d++;
|
|
|
+ iw.addDocument(mapper.documentMapper().parse(source(b -> {
|
|
|
+ b.field("doc", doc);
|
|
|
+ if (c != null) {
|
|
|
+ b.field(CONTENT_TYPE, c);
|
|
|
+ }
|
|
|
+ })).rootDoc());
|
|
|
+ }
|
|
|
+ }, reader -> {
|
|
|
+ SourceLoader loader = mapper.mappingLookup().newSourceLoader();
|
|
|
+ assertTrue(loader.requiredStoredFields().isEmpty());
|
|
|
+ for (LeafReaderContext leaf : reader.leaves()) {
|
|
|
+ int[] docIds = IntStream.range(0, leaf.reader().maxDoc()).toArray();
|
|
|
+ SourceLoader.Leaf sourceLoaderLeaf = loader.leaf(leaf.reader(), docIds);
|
|
|
+ LeafStoredFieldLoader storedFieldLoader = StoredFieldLoader.empty().getLoader(leaf, docIds);
|
|
|
+ for (int docId : docIds) {
|
|
|
+ String source = sourceLoaderLeaf.source(storedFieldLoader, docId).internalSourceRef().utf8ToString();
|
|
|
+ int doc = (int) JsonXContent.jsonXContent.createParser(XContentParserConfiguration.EMPTY, source).map().get("doc");
|
|
|
+ String docCountPart = counts.get(doc) == null ? "" : "\"_doc_count\":" + counts.get(doc) + ",";
|
|
|
+ assertThat("doc " + docId, source, equalTo("{" + docCountPart + "\"doc\":" + doc + "}"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|