Skip to content

Commit c9f0d93

Browse files
authored
Fix synthetic source issue with deeply nested ignored source fields (elastic#121715) (elastic#121792)
* Fix synthetic source issue with deeply nested ignored source fields * Update docs/changelog/121715.yaml
1 parent 3d6698b commit c9f0d93

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

docs/changelog/121715.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 121715
2+
summary: Fix synthetic source issue with deeply nested ignored source fields
3+
area: Mapping
4+
type: bug
5+
issues: []

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ public boolean setIgnoredValues(Map<String, List<IgnoredSourceFieldMapper.NameVa
11301130
for (SourceLoader.SyntheticFieldLoader loader : fields) {
11311131
ignoredValuesPresent |= loader.setIgnoredValues(objectsWithIgnoredFields);
11321132
}
1133-
return this.ignoredValues != null;
1133+
return ignoredValuesPresent;
11341134
}
11351135

11361136
@Override

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,6 +2420,34 @@ public void testStoredArrayWithFlatFields() throws IOException {
24202420
{"outer":{"inner":[{"a.b":"a.b","a.c":"a.c"}]}}""", syntheticSource);
24212421
}
24222422

2423+
public void testSingleDeepIgnoredField() throws IOException {
2424+
DocumentMapper documentMapper = createSytheticSourceMapperService(mapping(b -> {
2425+
b.startObject("top");
2426+
b.startObject("properties");
2427+
{
2428+
b.startObject("level1").startObject("properties");
2429+
{
2430+
b.startObject("level2").startObject("properties");
2431+
{
2432+
b.startObject("n")
2433+
.field("type", "integer")
2434+
.field("doc_values", "false")
2435+
.field("synthetic_source_keep", "all")
2436+
.endObject();
2437+
}
2438+
b.endObject().endObject();
2439+
}
2440+
b.endObject().endObject();
2441+
}
2442+
b.endObject().endObject();
2443+
})).documentMapper();
2444+
2445+
var syntheticSource = syntheticSource(documentMapper, b -> {
2446+
b.startObject("top").startObject("level1").startObject("level2").field("n", 25).endObject().endObject().endObject();
2447+
});
2448+
assertEquals("{\"top\":{\"level1\":{\"level2\":{\"n\":25}}}}", syntheticSource);
2449+
}
2450+
24232451
protected void validateRoundTripReader(String syntheticSource, DirectoryReader reader, DirectoryReader roundTripReader)
24242452
throws IOException {
24252453
// We exclude ignored source field since in some cases it contains an exact copy of a part of document source.

0 commit comments

Comments
 (0)