dynamic
When you index a document containing a new field, Elasticsearch 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:
PUT my-index-000001/_doc/1
{
"username": "johnsmith",
"name": {
"first": "John",
"last": "Smith"
}
}
GET my-index-000001/_mapping | Refer to fields under the | |
| Check the mapping to view changes. |
The following document adds two string fields: email and name.middle:
PUT my-index-000001/_doc/2
{
"username": "marywhite",
"email": "mary@white.com",
"name": {
"first": "Mary",
"middle": "Alice",
"last": "White"
}
}
GET my-index-000001/_mapping Setting dynamic on inner objects
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.
However, the user.social_networks object enables dynamic mapping, so you can add fields to this inner object.
PUT my-index-000001
{
"mappings": {
"dynamic": false,
"properties": {
"user": {
"properties": {
"name": {
"type": "text"
},
"social_networks": {
"dynamic": true,
"properties": {}
}
}
}
}
}
} | Disables dynamic mapping at the type level. | |
| The | |
| Enables dynamic mapping for this inner object. |
Parameters for dynamic
The dynamic parameter controls whether new fields are added dynamically, and accepts the following parameters:
| | New fields are added to the mapping (default). |
| | New fields are added to the mapping as runtime fields. These fields are not indexed, and are loaded from |
| | New fields are ignored. These fields will not be indexed or 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. |
© 2023-2025 Elasticsearch
As of September 2024, Elasticsearch is available under a choice of three licenses: the Server Side Public License (SSPL), the Elastic License, or the AGPLv3 (OSI approved).
Elasticsearch and the Elasticsearch logo are trademarks of Elasticsearch B.V., registered in the U.S. and in other countries.
https://www.elastic.co/guide/en/elasticsearch/reference/7.17/dynamic.html