-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Add documentation for passthrough field type #114720
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
kkrik-es
merged 19 commits into
elastic:main
from
kkrik-es:synthetic-source/second-pass-flag
Oct 15, 2024
Merged
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
363143f
Guard second doc parsing pass with index setting
kkrik-es aba471e
add test
kkrik-es eeea953
updates
kkrik-es c55f8c9
updates
kkrik-es f5c4501
Merge branch 'main' into synthetic-source/second-pass-flag
kkrik-es a0e09c6
merge
kkrik-es 8fbddca
Add documentation for passthrough field type
kkrik-es 89bcc42
Merge branch 'main' into synthetic-source/second-pass-flag
kkrik-es 0f67b34
Merge branch 'elastic:main' into synthetic-source/second-pass-flag
kkrik-es c46f72f
Apply suggestions from code review
kkrik-es ee26d09
Merge branch 'main' into synthetic-source/second-pass-flag
kkrik-es 4a5542e
updates
kkrik-es 8f795d4
updates
kkrik-es db939e0
Merge branch 'elastic:main' into synthetic-source/second-pass-flag
kkrik-es 442d3f1
Update docs/reference/mapping/types/passthrough.asciidoc
kkrik-es dead0e1
address comment
kkrik-es b0d97d4
address comment
kkrik-es db68fef
Update docs/reference/mapping/types/passthrough.asciidoc
kkrik-es 9da1ae0
address comment
kkrik-es 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
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
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,218 @@ | ||
[[passthrough]] | ||
=== Pass-through object field type | ||
++++ | ||
<titleabbrev>Pass-through object</titleabbrev> | ||
++++ | ||
|
||
Pass-through objects extend the functionality of <<object, objects>> by allowing to access | ||
their subfields without including the name of the pass-through object as prefix. For instance: | ||
|
||
[source,console] | ||
-------------------------------------------------- | ||
PUT my-index-000001 | ||
{ | ||
"mappings": { | ||
"properties": { | ||
"attributes": { | ||
"type": "passthrough", <1> | ||
"priority": 10, | ||
"properties": { | ||
"id": { | ||
"type": "keyword" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
PUT my-index-000001/_doc/1 | ||
{ | ||
"attributes" : { <2> | ||
"id": "foo", | ||
"zone": 10 | ||
} | ||
} | ||
|
||
GET my-index-000001/_search | ||
{ | ||
"query": { | ||
"bool": { | ||
"must": [ | ||
{ "match": { "id": "foo" }}, <3> | ||
{ "match": { "zone": 10 }} | ||
] | ||
} | ||
} | ||
} | ||
|
||
GET my-index-000001/_search | ||
{ | ||
"query": { | ||
"bool": { | ||
"must": [ | ||
{ "match": { "attributes.id": "foo" }}, <4> | ||
{ "match": { "attributes.zone": 10 }} | ||
] | ||
} | ||
} | ||
} | ||
|
||
-------------------------------------------------- | ||
|
||
<1> An object is defined as pass-through. Its priority (required) is used for conflict resolution. | ||
<2> Object contents get indexed as usual, including dynamic mappings. | ||
<3> Sub-fields can be referenced in queries as if they're defined at the root level. | ||
<4> Sub-fields can also be referenced including the object name as prefix. | ||
|
||
[[passthrough-conflicts]] | ||
==== Conflict resolution | ||
|
||
It's possible for conflicting names to arise, for fields that are defined within different scopes: | ||
|
||
1. A pass-through object is defined next to a field that has the same name as one of the pass-through object | ||
sub-fields, e.g. | ||
|
||
[source,console] | ||
-------------------------------------------------- | ||
PUT my-index-000001/_doc/1 | ||
{ | ||
"attributes" : { | ||
"id": "foo" | ||
}, | ||
"id": "bar" | ||
} | ||
-------------------------------------------------- | ||
|
||
In this case, references to `id` point to the field at the root level, while field `attributes.id` | ||
can only be accessed using the full path. | ||
|
||
1. Two (or more) pass-through objects are defined within the same object and contain fields with the same name, e.g. | ||
|
||
[source,console] | ||
-------------------------------------------------- | ||
PUT my-index-000002 | ||
{ | ||
"mappings": { | ||
"properties": { | ||
"attributes": { | ||
"type": "passthrough", | ||
"priority": 10, | ||
"properties": { | ||
"id": { | ||
"type": "keyword" | ||
} | ||
} | ||
}, | ||
"resource.attributes": { | ||
"type": "passthrough", | ||
"priority": 20, | ||
"properties": { | ||
"id": { | ||
"type": "keyword" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
-------------------------------------------------- | ||
|
||
In this case, param `priority` is used for conflict resolution, with the higher values taking precedence. In the | ||
example above, `attributes` has higher priority than `resource.attributes`, so references to `id` point to the field | ||
within `attributes`. `resource.attributes.id` can still be accessed using its full path. | ||
kkrik-es marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
[[passthrough-dimensions]] | ||
==== Defining sub-fields as time-series dimensions | ||
|
||
It is possible to configure a pass-through field as a container for <<time-series-dimension,time-series dimensions>>. | ||
In this case, all sub-fields get annotated with the same parameter under the covers, and they're also | ||
included in <<dimension-based-routing, routing path>> and <<tsid, tsid>> calculations, thus simplifying | ||
the <<tsds,TSDS>> setup: | ||
|
||
[source,console] | ||
-------------------------------------------------- | ||
PUT _index_template/my-metrics | ||
{ | ||
"index_patterns": ["metrics-mymetrics-*"], | ||
"priority": 200, | ||
"data_stream": { }, | ||
"template": { | ||
"settings": { | ||
"index.mode": "time_series" | ||
}, | ||
"mappings": { | ||
"properties": { | ||
"attributes": { | ||
"type": "passthrough", | ||
"priority": 10, | ||
"time_series_dimension": true, | ||
"properties": { | ||
"host": { | ||
"type": "keyword" | ||
} | ||
} | ||
}, | ||
"cpu": { | ||
"type": "integer", | ||
"time_series_metric": "counter" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
POST metrics-mymetrics-test/_doc | ||
{ | ||
"@timestamp": "2020-01-01T00:00:00.000Z", | ||
"attributes" : { | ||
"host": "foo", | ||
"zone": "bar" | ||
}, | ||
"cpu": 10 | ||
} | ||
-------------------------------------------------- | ||
// TEST[skip: The @timestamp value won't match an accepted range in the TSDS] | ||
|
||
In the example above, `attributes` is defined as a dimension container. Its sub-fields `host` (static) and `zone` | ||
(dynamic) get included in the routing path and tsid, and can be referenced in queries without the `attributes.` prefix. | ||
|
||
[[passthrough-flattening]] | ||
==== Sub-field auto-flattening | ||
|
||
Pass-through fields apply <<subobjects-auto-flattening, auto-flattening>> to sub-fields by default, to reduce dynamic | ||
mapping conflicts. As a consequence, no sub-object definitions are allowed within pass-through fields. | ||
felixbarny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[[passthrough-params]] | ||
==== Parameters for `passthrough` fields | ||
felixbarny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The following parameters are accepted by `passthrough` fields: | ||
|
||
[horizontal] | ||
|
||
<<priority,`priority`>>:: | ||
kkrik-es marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
(Required) used for naming conflict resolution between pass-through fields. The field with the highest value wins. | ||
Accepts non-negative integer values. | ||
|
||
<<time_series_dimension,`time_series_dimension`>>:: | ||
|
||
Whether or not to treat sub-fields as <<time-series-dimension,time-series dimensions>>. | ||
Accepts `false` (default) or `true`. | ||
|
||
<<dynamic,`dynamic`>>:: | ||
|
||
Whether or not new `properties` should be added dynamically to an existing object. | ||
Accepts `true` (default), `runtime`, `false` and `strict`. | ||
|
||
<<enabled,`enabled`>>:: | ||
|
||
Whether the JSON value given for the object field should be parsed and indexed (`true`, default) | ||
or completely ignored (`false`). | ||
|
||
<<properties,`properties`>>:: | ||
|
||
The fields within the object, which can be of any <<mapping-types,data type>>, including `object`. | ||
New properties may be added to an existing object. | ||
|
||
IMPORTANT: If you need to index arrays of objects instead of single objects, read <<nested>> first. |
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
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.