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-000001/_doc/1 { "username": "johnsmith", "name": { "first": "John", "last": "Smith" } } GET my-index-000001/_mapping PUT my-index-000001/_doc/2 { "username": "marywhite", "email": "[email protected]", "name": { "first": "Mary", "middle": "Alice", "last": "White" } } GET my-index-000001/_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. These fields will not be indexed so will not be searchable
but will still appear in the |
|
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
inner object. Inner objects inherit the setting from their parent
object or from the mapping type. For instance:
PUT my-index-000001 { "mappings": { "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 can be updated on existing fields
using the PUT mapping API.