原英文版地址: https://www.elastic.co/guide/en/elasticsearch/reference/7.7/coerce.html, 原文档版权归 www.elastic.co 所有
本地英文版地址: ../en/coerce.html
本地英文版地址: ../en/coerce.html
重要: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 当前版本文档。
coerce
edit
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 datatype of a field. For instance:
- Strings will be coerced to numbers.
- Floating points will be truncated for integer values.
For instance:
PUT my_index { "mappings": { "properties": { "number_one": { "type": "integer" }, "number_two": { "type": "integer", "coerce": false } } } } PUT my_index/_doc/1 { "number_one": "10" } PUT my_index/_doc/2 { "number_two": "10" }
The |
|
This document will be rejected because coercion is disabled. |
The coerce
setting value can be updated on existing fields
using the PUT mapping API.
Index-level defaultedit
The index.mapping.coerce
setting can be set on the index level to disable
coercion globally across all mapping types: