@@ -342,9 +342,14 @@ public void testIgnoredArray() throws IOException {
342342 public void testEncodeFieldToMap () throws IOException {
343343 String value = randomAlphaOfLength (5 );
344344 ParsedDocument parsedDocument = getParsedDocumentWithFieldLimit (b -> b .field ("my_value" , value ));
345- byte [] bytes = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .ignoredFieldName ("my_value" )).binaryValue ().bytes ;
346- IgnoredSourceFieldMapper .MappedNameValue mappedNameValue = IgnoredSourceFieldMapper .decodeAsMapMultipleFieldValues (bytes )
347- .getFirst ();
345+ IgnoredSourceFieldMapper .MappedNameValue mappedNameValue ;
346+ if (IgnoredSourceFieldMapper .IGNORED_SOURCE_FIELDS_PER_ENTRY_FF .isEnabled ()) {
347+ byte [] bytes = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .ignoredFieldName ("my_value" )).binaryValue ().bytes ;
348+ mappedNameValue = IgnoredSourceFieldMapper .decodeAsMapMultipleFieldValues (bytes ).getFirst ();
349+ } else {
350+ byte [] bytes = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .NAME ).binaryValue ().bytes ;
351+ mappedNameValue = IgnoredSourceFieldMapper .decodeAsMap (bytes );
352+ }
348353 assertEquals ("my_value" , mappedNameValue .nameValue ().name ());
349354 assertEquals (value , mappedNameValue .map ().get ("my_value" ));
350355 }
@@ -355,13 +360,23 @@ public void testEncodeObjectToMapAndDecode() throws IOException {
355360 ParsedDocument parsedDocument = getParsedDocumentWithFieldLimit (
356361 b -> { b .startObject ("my_object" ).field ("my_value" , value ).endObject (); }
357362 );
358- var byteRef = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .ignoredFieldName ("my_object" )).binaryValue ();
359- byte [] bytes = ArrayUtil .copyOfSubArray (byteRef .bytes , byteRef .offset , byteRef .length );
360- IgnoredSourceFieldMapper .MappedNameValue mappedNameValue = IgnoredSourceFieldMapper .decodeAsMapMultipleFieldValues (bytes )
361- .getFirst ();
363+ byte [] bytes ;
364+ IgnoredSourceFieldMapper .MappedNameValue mappedNameValue ;
365+ if (IgnoredSourceFieldMapper .IGNORED_SOURCE_FIELDS_PER_ENTRY_FF .isEnabled ()) {
366+ var byteRef = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .ignoredFieldName ("my_object" )).binaryValue ();
367+ bytes = ArrayUtil .copyOfSubArray (byteRef .bytes , byteRef .offset , byteRef .length );
368+ mappedNameValue = IgnoredSourceFieldMapper .decodeAsMapMultipleFieldValues (bytes ).getFirst ();
369+ } else {
370+ bytes = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .NAME ).binaryValue ().bytes ;
371+ mappedNameValue = IgnoredSourceFieldMapper .decodeAsMap (bytes );
372+ }
362373 assertEquals ("my_object" , mappedNameValue .nameValue ().name ());
363374 assertEquals (value , ((Map <String , ?>) mappedNameValue .map ().get ("my_object" )).get ("my_value" ));
364- assertArrayEquals (bytes , IgnoredSourceFieldMapper .encodeFromMapMultipleFieldValues (List .of (mappedNameValue )));
375+ if (IgnoredSourceFieldMapper .IGNORED_SOURCE_FIELDS_PER_ENTRY_FF .isEnabled ()) {
376+ assertArrayEquals (bytes , IgnoredSourceFieldMapper .encodeFromMapMultipleFieldValues (List .of (mappedNameValue )));
377+ } else {
378+ assertArrayEquals (bytes , IgnoredSourceFieldMapper .encodeFromMap (mappedNameValue ));
379+ }
365380 }
366381
367382 public void testEncodeArrayToMapAndDecode () throws IOException {
@@ -371,13 +386,23 @@ public void testEncodeArrayToMapAndDecode() throws IOException {
371386 b .startObject ().field ("int_value" , 20 ).endObject ();
372387 b .endArray ();
373388 });
374- var byteRef = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .ignoredFieldName ("my_array" )).binaryValue ();
375- byte [] bytes = ArrayUtil .copyOfSubArray (byteRef .bytes , byteRef .offset , byteRef .length );
376- IgnoredSourceFieldMapper .MappedNameValue mappedNameValue = IgnoredSourceFieldMapper .decodeAsMapMultipleFieldValues (bytes )
377- .getFirst ();
389+ byte [] bytes ;
390+ IgnoredSourceFieldMapper .MappedNameValue mappedNameValue ;
391+ if (IgnoredSourceFieldMapper .IGNORED_SOURCE_FIELDS_PER_ENTRY_FF .isEnabled ()) {
392+ var byteRef = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .ignoredFieldName ("my_array" )).binaryValue ();
393+ bytes = ArrayUtil .copyOfSubArray (byteRef .bytes , byteRef .offset , byteRef .length );
394+ mappedNameValue = IgnoredSourceFieldMapper .decodeAsMapMultipleFieldValues (bytes ).getFirst ();
395+ } else {
396+ bytes = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .NAME ).binaryValue ().bytes ;
397+ mappedNameValue = IgnoredSourceFieldMapper .decodeAsMap (bytes );
398+ }
378399 assertEquals ("my_array" , mappedNameValue .nameValue ().name ());
379400 assertThat ((List <?>) mappedNameValue .map ().get ("my_array" ), Matchers .contains (Map .of ("int_value" , 10 ), Map .of ("int_value" , 20 )));
380- assertArrayEquals (bytes , IgnoredSourceFieldMapper .encodeFromMapMultipleFieldValues (List .of (mappedNameValue )));
401+ if (IgnoredSourceFieldMapper .IGNORED_SOURCE_FIELDS_PER_ENTRY_FF .isEnabled ()) {
402+ assertArrayEquals (bytes , IgnoredSourceFieldMapper .encodeFromMapMultipleFieldValues (List .of (mappedNameValue )));
403+ } else {
404+ assertArrayEquals (bytes , IgnoredSourceFieldMapper .encodeFromMap (mappedNameValue ));
405+ }
381406 }
382407
383408 public void testMultipleIgnoredFieldsRootObject () throws IOException {
@@ -2464,10 +2489,16 @@ public void testSingleDeepIgnoredField() throws IOException {
24642489 assertEquals ("{\" top\" :{\" level1\" :{\" level2\" :{\" n\" :25}}}}" , syntheticSource );
24652490 }
24662491
2492+ private static String getIgnoredSourceFieldMask () {
2493+ return IgnoredSourceFieldMapper .IGNORED_SOURCE_FIELDS_PER_ENTRY_FF .isEnabled ()
2494+ ? IgnoredSourceFieldMapper .ignoredFieldName ("*" )
2495+ : IgnoredSourceFieldMapper .NAME ;
2496+ }
2497+
24672498 private final Set <String > roundtripMaskedFields = Set .of (
24682499 SourceFieldMapper .RECOVERY_SOURCE_NAME ,
24692500 SourceFieldMapper .RECOVERY_SOURCE_SIZE_NAME ,
2470- IgnoredSourceFieldMapper . NAME + ".*" ,
2501+ getIgnoredSourceFieldMask () ,
24712502 "*.offsets"
24722503 );
24732504
0 commit comments