@@ -111,7 +111,7 @@ public int get() {
111111 private final Set <String > ignoredFields ;
112112 private final List <IgnoredSourceFieldMapper .NameValue > ignoredFieldValues ;
113113 private final List <IgnoredSourceFieldMapper .NameValue > ignoredFieldsMissingValues ;
114- private String parentArrayField ;
114+ private boolean inArrayScope ;
115115
116116 private final Map <String , List <Mapper >> dynamicMappers ;
117117 private final DynamicMapperSize dynamicMappersSize ;
@@ -143,7 +143,7 @@ private DocumentParserContext(
143143 Set <String > ignoreFields ,
144144 List <IgnoredSourceFieldMapper .NameValue > ignoredFieldValues ,
145145 List <IgnoredSourceFieldMapper .NameValue > ignoredFieldsWithNoSource ,
146- String parentArrayField ,
146+ boolean inArrayScope ,
147147 Map <String , List <Mapper >> dynamicMappers ,
148148 Map <String , ObjectMapper > dynamicObjectMappers ,
149149 Map <String , List <RuntimeField >> dynamicRuntimeFields ,
@@ -164,7 +164,7 @@ private DocumentParserContext(
164164 this .ignoredFields = ignoreFields ;
165165 this .ignoredFieldValues = ignoredFieldValues ;
166166 this .ignoredFieldsMissingValues = ignoredFieldsWithNoSource ;
167- this .parentArrayField = parentArrayField ;
167+ this .inArrayScope = inArrayScope ;
168168 this .dynamicMappers = dynamicMappers ;
169169 this .dynamicObjectMappers = dynamicObjectMappers ;
170170 this .dynamicRuntimeFields = dynamicRuntimeFields ;
@@ -188,7 +188,7 @@ private DocumentParserContext(ObjectMapper parent, ObjectMapper.Dynamic dynamic,
188188 in .ignoredFields ,
189189 in .ignoredFieldValues ,
190190 in .ignoredFieldsMissingValues ,
191- in .parentArrayField ,
191+ in .inArrayScope ,
192192 in .dynamicMappers ,
193193 in .dynamicObjectMappers ,
194194 in .dynamicRuntimeFields ,
@@ -219,7 +219,7 @@ protected DocumentParserContext(
219219 new HashSet <>(),
220220 new ArrayList <>(),
221221 new ArrayList <>(),
222- null ,
222+ false ,
223223 new HashMap <>(),
224224 new HashMap <>(),
225225 new HashMap <>(),
@@ -324,10 +324,7 @@ public final void deduplicateIgnoredFieldValues(final Set<String> fullNames) {
324324 public final DocumentParserContext addIgnoredFieldFromContext (IgnoredSourceFieldMapper .NameValue ignoredFieldWithNoSource )
325325 throws IOException {
326326 if (canAddIgnoredField ()) {
327- if (parentArrayField != null
328- && parent != null
329- && parentArrayField .equals (parent .fullPath ())
330- && parent instanceof NestedObjectMapper == false ) {
327+ if (inArrayScope ) {
331328 // The field is an array within an array, store all sub-array elements.
332329 ignoredFieldsMissingValues .add (ignoredFieldWithNoSource );
333330 return cloneWithRecordedSource ();
@@ -364,14 +361,17 @@ public final Collection<IgnoredSourceFieldMapper.NameValue> getIgnoredFieldsMiss
364361 }
365362
366363 /**
367- * Clones the current context to mark it as an array. Records the full name of the array field, to check for sub-arrays .
364+ * Clones the current context to mark it as an array, if it's not already marked, or restore it if it's within a nested object .
368365 * Applies to synthetic source only.
369366 */
370- public final DocumentParserContext cloneForArray (String fullName ) throws IOException {
371- if (canAddIgnoredField ()) {
372- DocumentParserContext subcontext = switchParser (parser ());
373- subcontext .parentArrayField = fullName ;
374- return subcontext ;
367+ public final DocumentParserContext maybeCloneForArray (Mapper mapper ) throws IOException {
368+ if (canAddIgnoredField () && mapper instanceof ObjectMapper ) {
369+ boolean isNested = mapper instanceof NestedObjectMapper ;
370+ if ((inArrayScope == false && isNested == false ) || (inArrayScope && isNested )) {
371+ DocumentParserContext subcontext = switchParser (parser ());
372+ subcontext .inArrayScope = inArrayScope == false ;
373+ return subcontext ;
374+ }
375375 }
376376 return this ;
377377 }
0 commit comments