Skip to content

Commit 1b88505

Browse files
Make flattened synthetic source concatenate object keys on scalar/object mismatch (#129600) (#129792)
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.
1 parent a8e5a72 commit 1b88505

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/elasticsearch/mapping-reference/flattened.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,36 @@ Will become (note the nested objects instead of the "flattened" array):
364364
}
365365
}
366366
```
367+
368+
Flattened fields allow for a key to contain both an object and a scalar value.
369+
For example, consider the following flattened field `flattened`:
370+
371+
```console-result
372+
{
373+
"flattened": {
374+
"foo.bar": "10",
375+
"foo": {
376+
"bar": {
377+
"baz": "20"
378+
}
379+
}
380+
}
381+
}
382+
```
383+
384+
Because `"foo.bar": "10"` is implicitly equivalent to `"foo": { "bar": "10" }`,
385+
`"bar"` has both a scalar value `"10"`, and an object value of `{ "baz": "20" }`.
386+
387+
With synthetic source, to produce a valid JSON output, objects with such fields will appear differently in `_source`.
388+
For example, if the field is defined in an index configured with synthetic source, the value of `_source` would be:
389+
390+
```console-result
391+
{
392+
"flattened": {
393+
"foo": {
394+
"bar": "10",
395+
"bar.baz": "20"
396+
}
397+
}
398+
}
399+
```

0 commit comments

Comments
 (0)