-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[DOCS] Add dynamic runtime fields to docs #66194
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
lockewritesdocs
merged 4 commits into
elastic:master
from
lockewritesdocs:docs__dynamic-runtime-fields
Dec 14, 2020
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
[[dynamic]] | ||
=== `dynamic` | ||
|
||
By default, fields can be added _dynamically_ to a document, or to | ||
<<object,inner objects>> within a document, just by indexing a document | ||
containing the new field. For instance: | ||
When you index a document containing a new field, {es} <<dynamic-mapping,adds the field dynamically>> to a document or to inner objects within a document. The | ||
following document adds the string field `username`, the object field | ||
`name`, and two string fields under the `name` object: | ||
|
||
[source,console] | ||
-------------------------------------------------- | ||
PUT my-index-000001/_doc/1 <1> | ||
---- | ||
PUT my-index-000001/_doc/1 | ||
{ | ||
"username": "johnsmith", | ||
"name": { | ||
"name": { <1> | ||
"first": "John", | ||
"last": "Smith" | ||
} | ||
} | ||
|
||
GET my-index-000001/_mapping <2> | ||
---- | ||
<1> Refer to fields under the `name` object as `name.first` and `name.last`. | ||
<2> Check the mapping to view changes. | ||
|
||
The following document adds two string fields: `email` and `name.middle`: | ||
|
||
PUT my-index-000001/_doc/2 <3> | ||
[source,console] | ||
---- | ||
PUT my-index-000001/_doc/2 | ||
{ | ||
"username": "marywhite", | ||
"email": "[email protected]", | ||
|
@@ -29,35 +36,24 @@ PUT my-index-000001/_doc/2 <3> | |
} | ||
} | ||
|
||
GET my-index-000001/_mapping <4> | ||
-------------------------------------------------- | ||
|
||
<1> This document introduces the string field `username`, the object field | ||
`name`, and two string fields under the `name` object which can be | ||
referred to as `name.first` and `name.last`. | ||
<2> Check the mapping to verify the above. | ||
<3> This document adds two string fields: `email` and `name.middle`. | ||
<4> Check the mapping to verify the changes. | ||
GET my-index-000001/_mapping | ||
---- | ||
|
||
The details of how new fields are detected and added to the mapping is explained in <<dynamic-mapping>>. | ||
TIP: Use the <<indices-put-mapping,PUT mapping API>> to update the `dynamic` | ||
setting on existing fields. | ||
|
||
The `dynamic` setting controls whether new fields can be added dynamically or | ||
not. It accepts three settings: | ||
[[dynamic-inner-objects]] | ||
==== Setting `dynamic` on inner objects | ||
<<object,Inner objects>> inherit the `dynamic` setting from their parent | ||
object or from the mapping type. In the following example, dynamic mapping is | ||
disabled at the type level, so no new top-level fields will be added | ||
dynamically. | ||
|
||
[horizontal] | ||
`true`:: Newly detected fields are added to the mapping. (default) | ||
`false`:: Newly detected fields are ignored. These fields will not be indexed so will not be searchable | ||
but will still appear in the `_source` field of returned hits. These fields will not be added | ||
to the mapping, new fields must be added explicitly. | ||
`strict`:: If new fields are detected, an exception is thrown and the document is rejected. New fields | ||
must be explicitly added to the mapping. | ||
|
||
The `dynamic` setting may be set at the mapping type level, and on each | ||
<<object,inner object>>. Inner objects inherit the setting from their parent | ||
object or from the mapping type. For instance: | ||
However, the `user.social_networks` object enables dynamic mapping, so you can | ||
add fields to this inner object. | ||
|
||
[source,console] | ||
-------------------------------------------------- | ||
---- | ||
PUT my-index-000001 | ||
{ | ||
"mappings": { | ||
|
@@ -68,20 +64,32 @@ PUT my-index-000001 | |
"name": { | ||
"type": "text" | ||
}, | ||
"social_networks": { <3> | ||
"dynamic": true, | ||
"social_networks": { | ||
"dynamic": true, <3> | ||
"properties": {} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
-------------------------------------------------- | ||
---- | ||
lockewritesdocs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<1> Dynamic mapping is disabled at the type level, so no new top-level fields will be added dynamically. | ||
<1> Disables dynamic mapping at the type level. | ||
<2> The `user` object inherits the type-level setting. | ||
<3> The `user.social_networks` object enables dynamic mapping, so new fields may be added to this inner object. | ||
<3> Enables dynamic mapping for this inner object. | ||
|
||
TIP: The `dynamic` setting can be updated on existing fields | ||
using the <<indices-put-mapping,PUT mapping API>>. | ||
[[dynamic-parameters]] | ||
==== Parameters for `dynamic` | ||
The `dynamic` parameter controls whether new fields are added dynamically, and | ||
accepts the following parameters: | ||
|
||
[horizontal] | ||
`true`:: New fields are added to the mapping (default). | ||
`runtime`:: New fields are added to the mapping as <<runtime,runtime fields>>. | ||
These fields are not indexed, and are loaded from `_source` at query time. | ||
`false`:: New fields are ignored. These fields will not be indexed | ||
or searchable, but will still appear in the `_source` field of returned hits. These fields will not be added | ||
to the mapping, and new fields must be added explicitly. | ||
`strict`:: If new fields are detected, an exception is thrown and the document | ||
is rejected. New fields must be explicitly added to the mapping. |
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.