Skip to content

Commit 528ae1f

Browse files
committed
Make flattened synthetic source concatenate object keys on scalar/object mismatch (elastic#129600)
There is an issue where for Flattened fields with synthetic source, if there is a key with a scalar value, and a duplicate key with an object value, one of the values will be left out of the produced synthetic source. This fixes the issue by replacing the object with paths to each of its keys. These paths consist of the concatenation of all keys going down to a given scalar, joined by a period. For example, they are of the form foo.bar.baz. This applies recursively, so that every value within the object, no matter how nested, will be accessible through a full specified path. (cherry picked from commit 245dc07) # Conflicts: # docs/reference/elasticsearch/mapping-reference/flattened.md
1 parent cc51d5d commit 528ae1f

File tree

5 files changed

+255
-146
lines changed

5 files changed

+255
-146
lines changed

docs/changelog/129600.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pr: 129600
2+
summary: Make flattened synthetic source concatenate object keys on scalar/object
3+
mismatch
4+
area: Mapping
5+
type: bug
6+
issues:
7+
- 122936

docs/reference/mapping/types/flattened.asciidoc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,36 @@ Will become (note the nested objects instead of the "flattened" array):
449449
}
450450
----
451451
// TEST[s/^/{"_source":/ s/\n$/}/]
452+
453+
Flattened fields allow for a key to contain both an object and a scalar value.
454+
For example, consider the following flattened field `flattened`:
455+
[source,console-result]
456+
----
457+
{
458+
"flattened": {
459+
"foo.bar": "10",
460+
"foo": {
461+
"bar": {
462+
"baz": "20"
463+
}
464+
}
465+
}
466+
}
467+
----
468+
469+
Because `"foo.bar": "10"` is implicitly equivalent to `"foo": { "bar": "10" }`,
470+
`"bar"` has both a scalar value `"10"`, and an object value of `{ "baz": "20" }`.
471+
472+
With synthetic source, to produce a valid JSON output, objects with such fields will appear differently in `_source`.
473+
For example, if the field is defined in an index configured with synthetic source, the value of `_source` would be:
474+
[source,console-result]
475+
----
476+
{
477+
"flattened": {
478+
"foo": {
479+
"bar": "10",
480+
"bar.baz": "20"
481+
}
482+
}
483+
}
484+
----

0 commit comments

Comments
 (0)