1010package org .elasticsearch .index .mapper ;
1111
1212import org .apache .lucene .index .DirectoryReader ;
13+ import org .apache .lucene .util .ArrayUtil ;
1314import org .elasticsearch .common .settings .Settings ;
1415import org .elasticsearch .core .CheckedConsumer ;
1516import org .elasticsearch .core .Nullable ;
@@ -330,7 +331,7 @@ public void testIgnoredArray() throws IOException {
330331 public void testEncodeFieldToMap () throws IOException {
331332 String value = randomAlphaOfLength (5 );
332333 ParsedDocument parsedDocument = getParsedDocumentWithFieldLimit (b -> b .field ("my_value" , value ));
333- byte [] bytes = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .NAME + ". my_value" ).binaryValue ().bytes ;
334+ byte [] bytes = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .ignoredFieldName ( " my_value") ).binaryValue ().bytes ;
334335 IgnoredSourceFieldMapper .MappedNameValue mappedNameValue = IgnoredSourceFieldMapper .decodeAsMapMulti (bytes ).getFirst ();
335336 assertEquals ("my_value" , mappedNameValue .nameValue ().name ());
336337 assertEquals (value , mappedNameValue .map ().get ("my_value" ));
@@ -342,11 +343,12 @@ public void testEncodeObjectToMapAndDecode() throws IOException {
342343 ParsedDocument parsedDocument = getParsedDocumentWithFieldLimit (
343344 b -> { b .startObject ("my_object" ).field ("my_value" , value ).endObject (); }
344345 );
345- byte [] bytes = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .NAME ).binaryValue ().bytes ;
346- IgnoredSourceFieldMapper .MappedNameValue mappedNameValue = IgnoredSourceFieldMapper .decodeAsMap (bytes );
346+ var byteRef = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .ignoredFieldName ("my_object" )).binaryValue ();
347+ byte [] bytes = ArrayUtil .copyOfSubArray (byteRef .bytes , byteRef .offset , byteRef .length );
348+ IgnoredSourceFieldMapper .MappedNameValue mappedNameValue = IgnoredSourceFieldMapper .decodeAsMapMulti (bytes ).getFirst ();
347349 assertEquals ("my_object" , mappedNameValue .nameValue ().name ());
348350 assertEquals (value , ((Map <String , ?>) mappedNameValue .map ().get ("my_object" )).get ("my_value" ));
349- assertArrayEquals (bytes , IgnoredSourceFieldMapper .encodeFromMap ( mappedNameValue , mappedNameValue . map ( )));
351+ assertArrayEquals (bytes , IgnoredSourceFieldMapper .encodeFromMapMulti ( List . of ( mappedNameValue )));
350352 }
351353
352354 public void testEncodeArrayToMapAndDecode () throws IOException {
@@ -356,11 +358,12 @@ public void testEncodeArrayToMapAndDecode() throws IOException {
356358 b .startObject ().field ("int_value" , 20 ).endObject ();
357359 b .endArray ();
358360 });
359- byte [] bytes = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .NAME ).binaryValue ().bytes ;
360- IgnoredSourceFieldMapper .MappedNameValue mappedNameValue = IgnoredSourceFieldMapper .decodeAsMap (bytes );
361+ var byteRef = parsedDocument .rootDoc ().getField (IgnoredSourceFieldMapper .ignoredFieldName ("my_array" )).binaryValue ();
362+ byte [] bytes = ArrayUtil .copyOfSubArray (byteRef .bytes , byteRef .offset , byteRef .length );
363+ IgnoredSourceFieldMapper .MappedNameValue mappedNameValue = IgnoredSourceFieldMapper .decodeAsMapMulti (bytes ).getFirst ();
361364 assertEquals ("my_array" , mappedNameValue .nameValue ().name ());
362365 assertThat ((List <?>) mappedNameValue .map ().get ("my_array" ), Matchers .contains (Map .of ("int_value" , 10 ), Map .of ("int_value" , 20 )));
363- assertArrayEquals (bytes , IgnoredSourceFieldMapper .encodeFromMap ( mappedNameValue , mappedNameValue . map ( )));
366+ assertArrayEquals (bytes , IgnoredSourceFieldMapper .encodeFromMapMulti ( List . of ( mappedNameValue )));
364367 }
365368
366369 public void testMultipleIgnoredFieldsRootObject () throws IOException {
0 commit comments