Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/129580.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 129580
summary: Check prefixes when constructing synthetic source for flattened fields
area: Mapping
type: bug
issues:
- 129508
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ private static void writeObject(
final List<String> values
) throws IOException {
startObject(b, startPrefix.prefix);
if (currKeyValue.suffix.equals(nextKeyValue.suffix) == false) {
if (currKeyValue.prefix.equals(nextKeyValue.prefix) == false || currKeyValue.suffix.equals(nextKeyValue.suffix) == false) {
writeNestedObject(b, values, currKeyValue.suffix().suffix);
}
endObject(b, endPrefix.prefix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,23 @@ public void testSyntheticSourceWithOnlyIgnoredValues() throws IOException {
assertThat(syntheticSource, equalTo("{\"field\":{\"key1\":\"val1\",\"obj1\":{\"key2\":\"val2\",\"key3\":[\"val3\",\"val4\"]}}}"));
}

public void testSyntheticSourceWithCommonLeafField() throws IOException {
DocumentMapper mapper = createSytheticSourceMapperService(
mapping(b -> { b.startObject("field").field("type", "flattened").endObject(); })
).documentMapper();

var syntheticSource = syntheticSource(mapper, b -> {
b.startObject("field");
{
b.startObject("obj1").field("key", "foo").endObject();
b.startObject("obj2").field("key", "bar").endObject();
}
b.endObject();
});
assertThat(syntheticSource, equalTo("""
{"field":{"obj1":{"key":"foo"},"obj2":{"key":"bar"}}}"""));
}

@Override
protected boolean supportsCopyTo() {
return false;
Expand Down