3535import static org .hamcrest .Matchers .hasKey ;
3636import static org .hamcrest .Matchers .not ;
3737
38+ /**
39+ * Test that the {@link IgnoredSourceFieldLoader} loads the correct stored values.
40+ */
3841public class IgnoredSourceFieldLoaderTests extends ESTestCase {
3942 public void testSupports () {
4043 assertTrue (
@@ -70,6 +73,8 @@ public void testSupports() {
7073 }
7174
7275 public void testLoadSingle () throws IOException {
76+ // Note: normally the stored value is encoded in the ignored source format
77+ // (see IgnoredSourceFieldMapper#encodeMultipleValuesForField), but these tests are only verifying the loader, not the encoding.
7378 BytesRef value = new BytesRef ("lorem ipsum" );
7479 Document doc = new Document ();
7580 doc .add (new StoredField ("_ignored_source.foo" , value ));
@@ -89,8 +94,8 @@ public void testLoadMultiple() throws IOException {
8994 doc .add (new StoredField ("_ignored_source.foo" , fooValue ));
9095 doc .add (new StoredField ("_ignored_source.bar" , barValue ));
9196 testLoader (doc , Set .of ("foo" , "bar" ), storedFields -> {
92- assertThat (storedFields , hasEntry (equalTo ("foo" ), containsInAnyOrder (fooValue )));
93- assertThat (storedFields , hasEntry (equalTo ("bar" ), containsInAnyOrder (barValue )));
97+ assertThat (storedFields , hasEntry (equalTo ("_ignored_source. foo" ), containsInAnyOrder (fooValue )));
98+ assertThat (storedFields , hasEntry (equalTo ("_ignored_source. bar" ), containsInAnyOrder (barValue )));
9499 });
95100 }
96101
@@ -103,8 +108,8 @@ public void testLoadSubset() throws IOException {
103108 doc .add (new StoredField ("_ignored_source.bar" , barValue ));
104109
105110 testLoader (doc , Set .of ("foo" ), storedFields -> {
106- assertThat (storedFields , hasEntry (equalTo ("foo" ), containsInAnyOrder (fooValue )));
107- assertThat (storedFields , not (hasKey ("bar" )));
111+ assertThat (storedFields , hasEntry (equalTo ("_ignored_source. foo" ), containsInAnyOrder (fooValue )));
112+ assertThat (storedFields , not (hasKey ("_ignored_source. bar" )));
108113 });
109114 }
110115
@@ -121,6 +126,7 @@ private void testLoader(Document doc, Set<String> fieldsToLoad, Consumer<Map<Str
121126 IgnoredSourceFieldLoader loader = new IgnoredSourceFieldLoader (spec , false );
122127 var leafLoader = loader .getLoader (reader .leaves ().getFirst (), new int [] { 0 });
123128 leafLoader .advanceTo (0 );
129+ storedFieldsConsumer .accept (leafLoader .storedFields ());
124130 }
125131 }
126132 }
0 commit comments