-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Add support for dots in field names for metrics usecases #86166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
javanna
merged 33 commits into
elastic:master
from
javanna:enhancement/collapsed_objects
May 17, 2022
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
e4c9458
Add support for dots in field names for metrics usecases
javanna 5d34e0f
Merge branch 'main' into enhancement/collapsed_objects
javanna af1d3fa
checkstyle
javanna 64cb72b
iter
javanna b96ae79
add test
javanna 8d47bfe
spotless
javanna c6c3b2c
Merge branch 'main' into enhancement/collapsed_objects
javanna f825e00
more tests
javanna 7d12ca7
spotless
javanna 227fe53
iter
javanna 6175fc2
iter
javanna 9761211
spotless
javanna 33d570f
docs
javanna 5034bc1
Update docs/changelog/86166.yaml
javanna 4ebdd8f
Update docs/changelog/86166.yaml
javanna 7a6143d
Update docs/changelog/86166.yaml
javanna 3acbdfe
iter
javanna f48a4a1
add array of objects tests
javanna eab7d83
typo
javanna 4ddb176
rename
javanna a5b5f9c
line length
javanna 4df6111
changelog
javanna 1430aff
rename leftover
javanna 17bc4dd
spotless
javanna e5b0e20
Merge branch 'main' into enhancement/collapsed_objects
javanna ef89e05
iter
javanna df40355
changelog
javanna 9e48d1b
iter
javanna cd3a6e5
iter
javanna cc7b420
add yaml test
javanna 1ebb167
add test for synthetic source
javanna 153a150
add another test for synthetic source
javanna 6db29eb
update changelog
javanna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
pr: 86166 | ||
summary: Add support for dots in field names for metrics usecases | ||
area: Mapping | ||
type: feature | ||
issues: | ||
- 63530 | ||
highlight: | ||
title: Add support for dots in field names for metrics usecases | ||
body: |- | ||
Metrics data can often be made of several fields with dots in their names, | ||
sharing common prefixes, like in the following example: | ||
|
||
``` | ||
{ | ||
"metrics.time" : 10, | ||
"metrics.time.min" : 1, | ||
"metrics.time.max" : 500 | ||
} | ||
``` | ||
|
||
Such format causes a mapping conflict as the `metrics.time` holds a value, | ||
but it also needs to be mapped as an object in order to hold the `min` and | ||
`max` leaf fields. | ||
|
||
A new object mapping parameter called `subobjects`, which defaults to `true`, | ||
has been introduced to preserve dots in field names. An object with `subobjects` | ||
set to `false` can only ever hold leaf sub-fields and no further objects. The | ||
following example shows how it can be configured in the mappings for the | ||
`metrics` object: | ||
|
||
``` | ||
{ | ||
"mappings": { | ||
"properties" : { | ||
"metrics" : { | ||
"type" : "object", | ||
"subobjects" : false | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
With this configuration any child of `metrics` will be mapped unchanged, | ||
without expanding dots in field names to the corresponding object structure. | ||
That makes it possible to store the metrics document above. | ||
|
||
notable: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
[[subobjects]] | ||
=== `subobjects` | ||
|
||
When indexing a document or updating mappings, Elasticsearch accepts fields that contain dots in their names, | ||
which get expanded to their corresponding object structure. For instance, the field `metrics.time.max` | ||
is mapped as a `max` leaf field with a parent `time` object, belonging to its parent `metrics` object. | ||
|
||
The described default behaviour is reasonable for most scenarios, but causes problems in certain situations | ||
where for instance a field `metrics.time` holds a value too, which is common when indexing metrics data. | ||
A document holding a value for both `metrics.time.max` and `metrics.time` gets rejected given that `time` | ||
would need to be a leaf field to hold a value as well as an object to hold the `max` sub-field. | ||
|
||
The `subobjects` setting, which can be applied only to the top-level mapping definition and | ||
to <<object,`object`>> fields, disables the ability for an object to hold further subobjects and makes it possible | ||
to store documents where field names contain dots and share common prefixes. From the example above, if the object | ||
container `metrics` has `subobjects` set to `false`, it can hold values for both `time` and `time.max` directly | ||
without the need for any intermediate object, as dots in field names are preserved. | ||
|
||
[source,console] | ||
-------------------------------------------------- | ||
PUT my-index-000001 | ||
{ | ||
"mappings": { | ||
"properties": { | ||
"metrics": { | ||
"type": "object", | ||
"subobjects": false <1> | ||
} | ||
} | ||
} | ||
} | ||
|
||
PUT my-index-000001/_doc/metric_1 | ||
{ | ||
"metrics.time" : 100, <2> | ||
"metrics.time.min" : 10, | ||
"metrics.time.max" : 900 | ||
} | ||
|
||
PUT my-index-000001/_doc/metric_2 | ||
{ | ||
"metrics" : { | ||
"time" : 100, <3> | ||
"time.min" : 10, | ||
"time.max" : 900 | ||
} | ||
} | ||
|
||
GET my-index-000001/_mapping | ||
-------------------------------------------------- | ||
|
||
[source,console-result] | ||
-------------------------------------------------- | ||
{ | ||
"my-index-000001" : { | ||
"mappings" : { | ||
"properties" : { | ||
"metrics" : { | ||
"subobjects" : false, | ||
"properties" : { | ||
"time" : { | ||
"type" : "long" | ||
}, | ||
"time.min" : { <4> | ||
"type" : "long" | ||
}, | ||
"time.max" : { | ||
"type" : "long" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
-------------------------------------------------- | ||
|
||
<1> The `metrics` field cannot hold other objects. | ||
<2> Sample document holding flat paths | ||
<3> Sample document holding an object (configured to not hold subobjects) and its leaf sub-fields | ||
<4> The resulting mapping where dots in field names were preserved | ||
|
||
The entire mapping may be configured to not support subobjects as well, in which case the document can | ||
only ever hold leaf sub-fields: | ||
|
||
[source,console] | ||
-------------------------------------------------- | ||
PUT my-index-000001 | ||
{ | ||
"mappings": { | ||
"subobjects": false <1> | ||
} | ||
} | ||
|
||
PUT my-index-000001/_doc/metric_1 | ||
{ | ||
"time" : "100ms", <2> | ||
"time.min" : "10ms", | ||
"time.max" : "900ms" | ||
} | ||
|
||
-------------------------------------------------- | ||
|
||
<1> The entire mapping is configured to not support objects. | ||
<2> The document does not support objects | ||
|
||
The `subobjects` setting for existing fields and the top-level mapping definition cannot be updated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...api-spec/src/yamlRestTest/resources/rest-api-spec/test/index/91_metrics_no_subobjects.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
"Metrics indexing": | ||
- skip: | ||
version: " - 8.2.99" | ||
reason: added in 8.3.0 | ||
|
||
- do: | ||
indices.put_template: | ||
name: test | ||
body: | ||
index_patterns: test-* | ||
mappings: | ||
dynamic_templates: | ||
- no_subobjects: | ||
match: metrics | ||
mapping: | ||
type: object | ||
subobjects: false | ||
|
||
- do: | ||
index: | ||
index: test-1 | ||
id: 1 | ||
refresh: true | ||
body: | ||
{ metrics.time: 10, metrics.time.max: 100, metrics.time.min: 1 } | ||
|
||
- do: | ||
field_caps: | ||
index: test-1 | ||
fields: metrics.time* | ||
- match: {fields.metrics\.time.long.searchable: true} | ||
- match: {fields.metrics\.time.long.aggregatable: true} | ||
- match: {fields.metrics\.time\.max.long.searchable: true} | ||
- match: {fields.metrics\.time\.max.long.aggregatable: true} | ||
- match: {fields.metrics\.time\.min.long.searchable: true} | ||
- match: {fields.metrics\.time\.min.long.aggregatable: true} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.