WARNING: Version 2.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.
coerce
editcoerce
editData 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 datatype of a field. For instance:
- Strings will be coerced to numbers.
- Floating points will be truncated for integer values.
- Lon/lat geo-points will be normalized to a standard -180:180 / -90:90 coordinate system.
For instance:
PUT my_index { "mappings": { "my_type": { "properties": { "number_one": { "type": "integer" }, "number_two": { "type": "integer", "coerce": false } } } } } PUT my_index/my_type/1 { "number_one": "10" } PUT my_index/my_type/2 { "number_two": "10" }
The |
|
This document will be rejected because coercion is disabled. |
The coerce
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.
Index-level default
editThe index.mapping.coerce
setting can be set on the index level to disable
coercion globally across all mapping types: