Skip to content

Commit 28635f0

Browse files
authored
[8.16] Fix synthetic source issue with deeply nested ignored source fields (#121715) (#121790)
* Fix synthetic source issue with deeply nested ignored source fields (#121715) * Fix synthetic source issue with deeply nested ignored source fields * Update docs/changelog/121715.yaml * fix tests
1 parent a57a792 commit 28635f0

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
@@ -1083,7 +1083,7 @@ public boolean setIgnoredValues(Map<String, List<IgnoredSourceFieldMapper.NameVa
10831083
for (SourceLoader.SyntheticFieldLoader loader : fields) {
10841084
ignoredValuesPresent |= loader.setIgnoredValues(objectsWithIgnoredFields);
10851085
}
1086-
return this.ignoredValues != null;
1086+
return ignoredValuesPresent;
10871087
}
10881088

10891089
@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
@@ -2205,6 +2205,34 @@ public void testStoredArrayWithFlatFields() throws IOException {
22052205
{"outer":{"inner":[{"a.b":"a.b","a.c":"a.c"}]}}""", syntheticSource);
22062206
}
22072207

2208+
public void testSingleDeepIgnoredField() throws IOException {
2209+
DocumentMapper documentMapper = createMapperService(syntheticSourceMapping(b -> {
2210+
b.startObject("top");
2211+
b.startObject("properties");
2212+
{
2213+
b.startObject("level1").startObject("properties");
2214+
{
2215+
b.startObject("level2").startObject("properties");
2216+
{
2217+
b.startObject("n")
2218+
.field("type", "integer")
2219+
.field("doc_values", "false")
2220+
.field("synthetic_source_keep", "all")
2221+
.endObject();
2222+
}
2223+
b.endObject().endObject();
2224+
}
2225+
b.endObject().endObject();
2226+
}
2227+
b.endObject().endObject();
2228+
})).documentMapper();
2229+
2230+
var syntheticSource = syntheticSource(documentMapper, b -> {
2231+
b.startObject("top").startObject("level1").startObject("level2").field("n", 25).endObject().endObject().endObject();
2232+
});
2233+
assertEquals("{\"top\":{\"level1\":{\"level2\":{\"n\":25}}}}", syntheticSource);
2234+
}
2235+
22082236
protected void validateRoundTripReader(String syntheticSource, DirectoryReader reader, DirectoryReader roundTripReader)
22092237
throws IOException {
22102238
// 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)