Nik Everett 4b1c116461 Generate and run tests from the docs
Adds infrastructure so `gradle :docs:check` will extract tests from
snippets in the documentation and execute the tests. This is included
in `gradle check` so it should happen on CI and during a normal build.

By default each `// AUTOSENSE` snippet creates a unique REST test. These
tests are executed in a random order and the cluster is wiped between
each one. If multiple snippets chain together into a test you can annotate
all snippets after the first with `// TEST[continued]` to have the
generated tests for both snippets joined.

Snippets marked as `// TESTRESPONSE` are checked against the response
of the last action.

See docs/README.asciidoc for lots more.

Closes #12583. That issue is about catching bugs in the docs during build.
This catches *some* bugs in the docs during build which is a good start.
2016-05-05 13:58:03 -04:00

88 lines
2.6 KiB
Plaintext

[[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:
[source,js]
--------------------------------------------------
PUT my_index/my_type/1 <1>
{
"username": "johnsmith",
"name": {
"first": "John",
"last": "Smith"
}
}
GET my_index/_mapping <2>
PUT my_index/my_type/2 <3>
{
"username": "marywhite",
"email": "mary@white.com",
"name": {
"first": "Mary",
"middle": "Alice",
"last": "White"
}
}
GET my_index/_mapping <4>
--------------------------------------------------
// AUTOSENSE
<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.
The details of how new fields are detected and added to the mapping is explained in <<dynamic-mapping>>.
The `dynamic` setting controls whether new fields can be added dynamically or
not. It accepts three settings:
[horizontal]
`true`:: Newly detected fields are added to the mapping. (default)
`false`:: Newly detected fields are ignored. New fields must be added explicitly.
`strict`:: If new fields are detected, an exception is thrown and the document is rejected.
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:
[source,js]
--------------------------------------------------
PUT my_index
{
"mappings": {
"my_type": {
"dynamic": false, <1>
"properties": {
"user": { <2>
"properties": {
"name": {
"type": "text"
},
"social_networks": { <3>
"dynamic": true,
"properties": {}
}
}
}
}
}
}
}
--------------------------------------------------
// AUTOSENSE
<1> Dynamic mapping is disabled at the type level, so no new top-level fields will be added dynamically.
<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.
TIP: The `dynamic` setting is allowed to have different settings for fields of
the same name in the same index. Its value can be updated on existing fields
using the <<indices-put-mapping,PUT mapping API>>.