WARNING: Version 5.0 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
dynamic
editdynamic
editBy default, fields can be added dynamically to a document, or to inner objects within a document, just by indexing a document containing the new field. For instance:
PUT my_index/my_type/1 { "username": "johnsmith", "name": { "first": "John", "last": "Smith" } } GET my_index/_mapping PUT my_index/my_type/2 { "username": "marywhite", "email": "mary@white.com", "name": { "first": "Mary", "middle": "Alice", "last": "White" } } GET my_index/_mapping
This document introduces the string field |
|
Check the mapping to verify the above. |
|
This document adds two string fields: |
|
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:
|
Newly detected fields are added to the mapping. (default) |
|
Newly detected fields are ignored. New fields must be added explicitly. |
|
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
inner object. Inner objects inherit the setting from their parent
object or from the mapping type. For instance:
PUT my_index { "mappings": { "my_type": { "dynamic": false, "properties": { "user": { "properties": { "name": { "type": "text" }, "social_networks": { "dynamic": true, "properties": {} } } } } } } }
Dynamic mapping is disabled at the type level, so no new top-level fields will be added dynamically. |
|
The |
|
The |
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 PUT mapping API.