Skip to content

Commit c392437

Browse files
committed
Fix release tests
1 parent 5edc55b commit c392437

File tree

5 files changed

+75
-21
lines changed

5 files changed

+75
-21
lines changed

server/src/main/java/org/elasticsearch/index/mapper/MapperFeatures.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class MapperFeatures implements FeatureSpecification {
4747
static final NodeFeature BBQ_DISK_SUPPORT = new NodeFeature("mapper.bbq_disk_support");
4848
static final NodeFeature SEARCH_LOAD_PER_SHARD = new NodeFeature("mapper.search_load_per_shard");
4949
static final NodeFeature PATTERNED_TEXT = new NodeFeature("mapper.patterned_text");
50+
static final NodeFeature IGNORED_SOURCE_FIELDS_PER_ENTRY = new NodeFeature("mapper.ignored_source_fields_per_entry");
5051

5152
@Override
5253
public Set<NodeFeature> getTestFeatures() {
@@ -80,7 +81,8 @@ public Set<NodeFeature> getTestFeatures() {
8081
BBQ_DISK_SUPPORT,
8182
SEARCH_LOAD_PER_SHARD,
8283
SPARSE_VECTOR_INDEX_OPTIONS_FEATURE,
83-
PATTERNED_TEXT
84+
PATTERNED_TEXT,
85+
IGNORED_SOURCE_FIELDS_PER_ENTRY
8486
);
8587
}
8688
}

server/src/test/java/org/elasticsearch/index/mapper/IgnoredSourceFieldMapperTests.java

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

test/framework/src/main/java/org/elasticsearch/index/mapper/NativeArrayIntegrationTestCase.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,14 @@ public void testSynthesizeRandomArrayInNestedContext() throws Exception {
228228
var reader = searcher.getDirectoryReader();
229229
var document = reader.storedFields().document(0);
230230
Set<String> storedFieldNames = new LinkedHashSet<>(document.getFields().stream().map(IndexableField::name).toList());
231-
assertThat(storedFieldNames, contains("_ignored_source.parent.field"));
231+
assertThat(
232+
storedFieldNames,
233+
contains(
234+
IgnoredSourceFieldMapper.IGNORED_SOURCE_FIELDS_PER_ENTRY_FF.isEnabled()
235+
? IgnoredSourceFieldMapper.ignoredFieldName("parent.field")
236+
: IgnoredSourceFieldMapper.NAME
237+
)
238+
);
232239
assertThat(FieldInfos.getMergedFieldInfos(reader).fieldInfo("parent.field.offsets"), nullValue());
233240
}
234241
}
@@ -368,7 +375,15 @@ protected void verifySyntheticObjectArray(List<List<Object[]>> documents) throws
368375
var document = reader.storedFields().document(i);
369376
// Verify that there is ignored source because of leaf array being wrapped by object array:
370377
List<String> storedFieldNames = document.getFields().stream().map(IndexableField::name).toList();
371-
assertThat(storedFieldNames, contains("_id", "_ignored_source.object"));
378+
assertThat(
379+
storedFieldNames,
380+
contains(
381+
"_id",
382+
IgnoredSourceFieldMapper.IGNORED_SOURCE_FIELDS_PER_ENTRY_FF.isEnabled()
383+
? IgnoredSourceFieldMapper.ignoredFieldName("object")
384+
: IgnoredSourceFieldMapper.NAME
385+
)
386+
);
372387

373388
// Verify that there is no offset field:
374389
LeafReader leafReader = reader.leaves().get(0).reader();

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/FieldSubsetReaderTests.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,14 @@ public void testIgnoredSourceFilteringIntegration() throws Exception {
711711
iw.addDocuments(doc.docs());
712712
iw.close();
713713

714+
String ignoredSourceFieldPattern = IgnoredSourceFieldMapper.ignoredSourceFormat(
715+
indexVersion
716+
) == IgnoredSourceFieldMapper.IgnoredSourceFormat.PER_FIELD_IGNORED_SOURCE
717+
? IgnoredSourceFieldMapper.ignoredFieldName("*")
718+
: IgnoredSourceFieldMapper.NAME;
719+
714720
{
715-
Automaton automaton = Automatons.patterns(Arrays.asList("fieldA", IgnoredSourceFieldMapper.ignoredFieldName("*")));
721+
Automaton automaton = Automatons.patterns(Arrays.asList("fieldA", ignoredSourceFieldPattern));
716722
try (
717723
DirectoryReader indexReader = FieldSubsetReader.wrap(
718724
wrapInMockESDirectoryReader(DirectoryReader.open(directory)),
@@ -743,7 +749,7 @@ public void testIgnoredSourceFilteringIntegration() throws Exception {
743749
}
744750

745751
{
746-
Automaton automaton = Automatons.patterns(Arrays.asList("obj.fieldC", IgnoredSourceFieldMapper.ignoredFieldName("*")));
752+
Automaton automaton = Automatons.patterns(Arrays.asList("obj.fieldC", ignoredSourceFieldPattern));
747753
try (
748754
DirectoryReader indexReader = FieldSubsetReader.wrap(
749755
wrapInMockESDirectoryReader(DirectoryReader.open(directory)),
@@ -775,7 +781,7 @@ public void testIgnoredSourceFilteringIntegration() throws Exception {
775781
}
776782

777783
{
778-
Automaton automaton = Automatons.patterns(Arrays.asList("arr.fieldD", IgnoredSourceFieldMapper.ignoredFieldName("*")));
784+
Automaton automaton = Automatons.patterns(Arrays.asList("arr.fieldD", ignoredSourceFieldPattern));
779785
try (
780786
DirectoryReader indexReader = FieldSubsetReader.wrap(
781787
wrapInMockESDirectoryReader(DirectoryReader.open(directory)),

x-pack/plugin/logsdb/src/yamlRestTest/resources/rest-api-spec/test/20_ignored_source.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ setup:
33
- skip:
44
features: headers
55
- requires:
6-
cluster_features: [ "mapper.source.mode_from_index_setting" ]
6+
cluster_features: [ "mapper.source.mode_from_index_setting" , "mapper.ignored_source_fields_per_entry" ]
77
reason: "Source mode configured through index setting"
88

99
- do:

0 commit comments

Comments
 (0)