diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java b/server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java index e1c9d2eee5690..0ff754d953934 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java @@ -851,6 +851,7 @@ private static void parseNonDynamicArray( elements = Integer.MAX_VALUE; parseArray(context, lastFieldName); } else if (token == XContentParser.Token.VALUE_NULL) { + elements++; parseNullValue(context, lastFieldName); } else if (token == null) { throwEOFOnParseArray(arrayFieldName, context); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/IgnoredSourceFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/IgnoredSourceFieldMapperTests.java index 5e93243d9186c..205ff08c397b2 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/IgnoredSourceFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/IgnoredSourceFieldMapperTests.java @@ -542,6 +542,14 @@ public void testIndexStoredArraySourceSingleLeafElement() throws IOException { assertNull(doc.rootDoc().getField("_ignored_source")); } + public void testIndexStoredArraySourceSingleLeafElementAndNull() throws IOException { + DocumentMapper documentMapper = createMapperServiceWithStoredArraySource(syntheticSourceMapping(b -> { + b.startObject("value").field("type", "keyword").endObject(); + })).documentMapper(); + var syntheticSource = syntheticSource(documentMapper, b -> b.array("value", new String[] { "foo", null })); + assertEquals("{\"value\":[\"foo\",null]}", syntheticSource); + } + public void testIndexStoredArraySourceSingleObjectElement() throws IOException { DocumentMapper documentMapper = createMapperServiceWithStoredArraySource(syntheticSourceMapping(b -> { b.startObject("path").startObject("properties");