Skip to content

Commit 747663d

Browse files
authored
Fix synthetic source issue with deeply nested ignored source fields (#121715) (#121789)
* Fix synthetic source issue with deeply nested ignored source fields * Update docs/changelog/121715.yaml
1 parent ebc3026 commit 747663d

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
@@ -2193,6 +2193,34 @@ public void testStoredArrayWithFlatFields() throws IOException {
21932193
{"outer":{"inner":[{"a.b":"a.b","a.c":"a.c"}]}}""", syntheticSource);
21942194
}
21952195

2196+
public void testSingleDeepIgnoredField() throws IOException {
2197+
DocumentMapper documentMapper = createSytheticSourceMapperService(mapping(b -> {
2198+
b.startObject("top");
2199+
b.startObject("properties");
2200+
{
2201+
b.startObject("level1").startObject("properties");
2202+
{
2203+
b.startObject("level2").startObject("properties");
2204+
{
2205+
b.startObject("n")
2206+
.field("type", "integer")
2207+
.field("doc_values", "false")
2208+
.field("synthetic_source_keep", "all")
2209+
.endObject();
2210+
}
2211+
b.endObject().endObject();
2212+
}
2213+
b.endObject().endObject();
2214+
}
2215+
b.endObject().endObject();
2216+
})).documentMapper();
2217+
2218+
var syntheticSource = syntheticSource(documentMapper, b -> {
2219+
b.startObject("top").startObject("level1").startObject("level2").field("n", 25).endObject().endObject().endObject();
2220+
});
2221+
assertEquals("{\"top\":{\"level1\":{\"level2\":{\"n\":25}}}}", syntheticSource);
2222+
}
2223+
21962224
protected void validateRoundTripReader(String syntheticSource, DirectoryReader reader, DirectoryReader roundTripReader)
21972225
throws IOException {
21982226
// 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)