1010package org .elasticsearch .index .mapper ;
1111
1212import org .apache .lucene .index .DirectoryReader ;
13- import org .apache .lucene .util .ArrayUtil ;
1413import org .elasticsearch .common .Strings ;
1514import org .elasticsearch .common .settings .Settings ;
1615import org .elasticsearch .core .CheckedConsumer ;
@@ -343,11 +342,11 @@ public void testEncodeFieldToMap() throws IOException {
343342 String value = randomAlphaOfLength (5 );
344343 ParsedDocument parsedDocument = getParsedDocumentWithFieldLimit (b -> b .field ("my_value" , value ));
345344 IgnoredSourceFieldMapper .MappedNameValue mappedNameValue ;
346- byte [] bytes = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .NAME ).binaryValue (). bytes ;
345+ var bytes = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .NAME ).binaryValue ();
347346 if (IgnoredSourceFieldMapper .COALESCE_IGNORED_SOURCE_ENTRIES .isEnabled ()) {
348- mappedNameValue = IgnoredSourceFieldMapper .decodeAsMapMultipleFieldValues (bytes ).getFirst ();
347+ mappedNameValue = IgnoredSourceFieldMapper .CoalescedIgnoredSourceEncoding . decodeAsMap (bytes ).getFirst ();
349348 } else {
350- mappedNameValue = IgnoredSourceFieldMapper .decodeAsMap (bytes );
349+ mappedNameValue = IgnoredSourceFieldMapper .LegacyIgnoredSourceEncoding . decodeAsMap (bytes );
351350 }
352351 assertEquals ("my_value" , mappedNameValue .nameValue ().name ());
353352 assertEquals (value , mappedNameValue .map ().get ("my_value" ));
@@ -359,20 +358,19 @@ public void testEncodeObjectToMapAndDecode() throws IOException {
359358 ParsedDocument parsedDocument = getParsedDocumentWithFieldLimit (
360359 b -> { b .startObject ("my_object" ).field ("my_value" , value ).endObject (); }
361360 );
362- var byteRef = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .NAME ).binaryValue ();
363- byte [] bytes = ArrayUtil .copyOfSubArray (byteRef .bytes , byteRef .offset , byteRef .length );
361+ var bytes = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .NAME ).binaryValue ();
364362 IgnoredSourceFieldMapper .MappedNameValue mappedNameValue ;
365363 if (IgnoredSourceFieldMapper .COALESCE_IGNORED_SOURCE_ENTRIES .isEnabled ()) {
366- mappedNameValue = IgnoredSourceFieldMapper .decodeAsMapMultipleFieldValues (bytes ).getFirst ();
364+ mappedNameValue = IgnoredSourceFieldMapper .CoalescedIgnoredSourceEncoding . decodeAsMap (bytes ).getFirst ();
367365 } else {
368- mappedNameValue = IgnoredSourceFieldMapper .decodeAsMap (bytes );
366+ mappedNameValue = IgnoredSourceFieldMapper .LegacyIgnoredSourceEncoding . decodeAsMap (bytes );
369367 }
370368 assertEquals ("my_object" , mappedNameValue .nameValue ().name ());
371369 assertEquals (value , ((Map <String , ?>) mappedNameValue .map ().get ("my_object" )).get ("my_value" ));
372370 if (IgnoredSourceFieldMapper .COALESCE_IGNORED_SOURCE_ENTRIES .isEnabled ()) {
373- assertArrayEquals (bytes , IgnoredSourceFieldMapper .encodeFromMapMultipleFieldValues (List .of (mappedNameValue )));
371+ assertEquals (bytes , IgnoredSourceFieldMapper .CoalescedIgnoredSourceEncoding . encodeFromMap (List .of (mappedNameValue )));
374372 } else {
375- assertArrayEquals (bytes , IgnoredSourceFieldMapper .encodeFromMap (mappedNameValue ));
373+ assertEquals (bytes , IgnoredSourceFieldMapper . LegacyIgnoredSourceEncoding .encodeFromMap (mappedNameValue ));
376374 }
377375 }
378376
@@ -383,20 +381,19 @@ public void testEncodeArrayToMapAndDecode() throws IOException {
383381 b .startObject ().field ("int_value" , 20 ).endObject ();
384382 b .endArray ();
385383 });
386- var byteRef = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .NAME ).binaryValue ();
387- byte [] bytes = ArrayUtil .copyOfSubArray (byteRef .bytes , byteRef .offset , byteRef .length );
384+ var bytes = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .NAME ).binaryValue ();
388385 IgnoredSourceFieldMapper .MappedNameValue mappedNameValue ;
389386 if (IgnoredSourceFieldMapper .COALESCE_IGNORED_SOURCE_ENTRIES .isEnabled ()) {
390- mappedNameValue = IgnoredSourceFieldMapper .decodeAsMapMultipleFieldValues (bytes ).getFirst ();
387+ mappedNameValue = IgnoredSourceFieldMapper .CoalescedIgnoredSourceEncoding . decodeAsMap (bytes ).getFirst ();
391388 } else {
392- mappedNameValue = IgnoredSourceFieldMapper .decodeAsMap (bytes );
389+ mappedNameValue = IgnoredSourceFieldMapper .LegacyIgnoredSourceEncoding . decodeAsMap (bytes );
393390 }
394391 assertEquals ("my_array" , mappedNameValue .nameValue ().name ());
395392 assertThat ((List <?>) mappedNameValue .map ().get ("my_array" ), Matchers .contains (Map .of ("int_value" , 10 ), Map .of ("int_value" , 20 )));
396393 if (IgnoredSourceFieldMapper .COALESCE_IGNORED_SOURCE_ENTRIES .isEnabled ()) {
397- assertArrayEquals (bytes , IgnoredSourceFieldMapper .encodeFromMapMultipleFieldValues (List .of (mappedNameValue )));
394+ assertEquals (bytes , IgnoredSourceFieldMapper .CoalescedIgnoredSourceEncoding . encodeFromMap (List .of (mappedNameValue )));
398395 } else {
399- assertArrayEquals (bytes , IgnoredSourceFieldMapper .encodeFromMap (mappedNameValue ));
396+ assertEquals (bytes , IgnoredSourceFieldMapper . LegacyIgnoredSourceEncoding .encodeFromMap (mappedNameValue ));
400397 }
401398 }
402399
0 commit comments