Type to search.

dynamic

Serverless

Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Serverless interfaces and procedures might differ from classic Elastic Stack deployments.

Stack

The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

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:

JSON
PUT my-index-000001/_doc/1
{
  "username": "johnsmith",
  "name": {
    "first": "John",
    "last": "Smith"
  }
}
GET my-index-000001/_mapping
  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:

JSON
PUT my-index-000001/_doc/2
{
  "username": "marywhite",
  "email": "mary@white.com",
  "name": {
    "first": "Mary",
    "middle": "Alice",
    "last": "White"
  }
}
GET my-index-000001/_mapping

Inner objects inherit the dynamic setting from their parent object. 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.

JSON
PUT my-index-000001
{
  "mappings": {
    "dynamic": false,
    "properties": {
      "user": {
        "properties": {
          "name": {
            "type": "text"
          },
          "social_networks": {
            "dynamic": true,
            "properties": {}
          }
        }
      }
    }
  }
}
  1. Disables dynamic mapping at the type level.
  2. The user object inherits the type-level setting.
  3. Enables dynamic mapping for this inner object.

The dynamic parameter controls whether new fields are added dynamically, and accepts the following parameters:

true
New fields are added to the mapping (default).
runtime
New fields are added to the mapping as runtime fields. These fields are not indexed and are loaded from _source at query time. This option is not supported for columnar indices.
false
New fields are ignored and will not be indexed or searchable. These fields will not be added to the mapping, and any new fields must be added explicitly. For non-columnar indices, these fields will still appear in the _source field of returned hits.
Warning

If you configure "dynamic": false on a columnar index, new fields are not stored at all and will be lost.

strict
If new fields are detected, an exception is thrown and the document is rejected. New fields must be explicitly added to the mapping.

Setting dynamic to either true or runtime will only add dynamic fields until index.mapping.total_fields.limit is reached. By default, index requests for documents that would exceed the field limit will fail, unless index.mapping.total_fields.ignore_dynamic_beyond_limit is set to true. In that case, ignored fields are added to the _ignored metadata field. For more index setting details, refer to Mapping limit settings.