Type to search.

coerce

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.

Data is not always clean. Depending on how it is produced a number might be rendered in the JSON body as a true JSON number, e.g. 5, but it might also be rendered as a string, e.g. "5". Alternatively, a number that should be an integer might instead be rendered as a floating point, e.g. 5.0, or even "5.0".

Coercion attempts to clean up dirty values to fit the data type of a field. For instance:

  • Strings will be coerced to numbers.
  • Floating points will be truncated for integer values.

For instance:

JSON
PUT my-index-000001
{
  "mappings": {
    "properties": {
      "number_one": {
        "type": "integer"
      },
      "number_two": {
        "type": "integer",
        "coerce": false
      }
    }
  }
}
PUT my-index-000001/_doc/1
{
  "number_one": "10"
}
PUT my-index-000001/_doc/2
{
  "number_two": "10"
}
  1. The number_one field will contain the integer 10.
  2. This document will be rejected because coercion is disabled.
Tip

The coerce setting value can be updated on existing fields using the update mapping API.

The index.mapping.coerce setting can be set on the index level to disable coercion globally across all mapping types:

JSON
PUT my-index-000001
{
  "settings": {
    "index.mapping.coerce": false
  },
  "mappings": {
    "properties": {
      "number_one": {
        "type": "integer",
        "coerce": true
      },
      "number_two": {
        "type": "integer"
      }
    }
  }
}
PUT my-index-000001/_doc/1
{ "number_one": "10" }
PUT my-index-000001/_doc/2
{ "number_two": "10" }
  1. The number_one field overrides the index level setting to enable coercion.
  2. This document will be rejected because the number_two field inherits the index-level coercion setting.