@@ -208,6 +208,7 @@ private static List<IgnoredSourceFieldMapper.NameValue> parseDocForMissingValues
208208 XContentParser parser = context .parser ();
209209 XContentParser .Token currentToken = parser .nextToken ();
210210 List <String > path = new ArrayList <>();
211+ List <Boolean > isObjectInPath = new ArrayList <>(); // Tracks if path components correspond to an object or an array.
211212 String fieldName = null ;
212213 while (currentToken != null ) {
213214 while (currentToken != XContentParser .Token .FIELD_NAME ) {
@@ -218,11 +219,16 @@ private static List<IgnoredSourceFieldMapper.NameValue> parseDocForMissingValues
218219 parser .skipChildren ();
219220 } else {
220221 path .add (fieldName );
222+ isObjectInPath .add (currentToken == XContentParser .Token .START_OBJECT );
221223 }
222224 fieldName = null ;
223225 } else if (currentToken == XContentParser .Token .END_OBJECT || currentToken == XContentParser .Token .END_ARRAY ) {
224- if (currentToken == XContentParser .Token .END_OBJECT && path .isEmpty () == false ) {
226+ // Remove the path, if the scope type matches the one when the path was added.
227+ if (isObjectInPath .isEmpty () == false
228+ && (isObjectInPath .get (isObjectInPath .size () - 1 ) && currentToken == XContentParser .Token .END_OBJECT
229+ || isObjectInPath .get (isObjectInPath .size () - 1 ) == false && currentToken == XContentParser .Token .END_ARRAY )) {
225230 path .remove (path .size () - 1 );
231+ isObjectInPath .remove (isObjectInPath .size () - 1 );
226232 }
227233 fieldName = null ;
228234 }
@@ -237,7 +243,6 @@ private static List<IgnoredSourceFieldMapper.NameValue> parseDocForMissingValues
237243 if (leaf != null ) {
238244 parser .nextToken (); // Advance the parser to the value to be read.
239245 result .add (leaf .cloneWithValue (context .encodeFlattenedToken ()));
240- parser .nextToken (); // Skip the token ending the value.
241246 fieldName = null ;
242247 }
243248 currentToken = parser .nextToken ();
0 commit comments