布尔字段类型
布尔字段接受 JSON 的 true 和 false 值,也可以接受被解释为 true 或 false 的字符串
- False 值
false、"false"、""(空字符串)- True 值
true,"true"
例如
PUT my-index-000001
{
"mappings": {
"properties": {
"is_published": {
"type": "boolean"
}
}
}
}
POST my-index-000001/_doc/1?refresh
{
"is_published": "true"
}
GET my-index-000001/_search
{
"query": {
"term": {
"is_published": true
}
}
}
- 索引一个带有
"true"的文档,它会被解释为true。 - 搜索带有 JSON
true的文档。
诸如 terms 聚合之类的聚合在 key 中使用 1 和 0,在 key_as_string 中使用字符串 "true" 和 "false"。布尔字段在脚本中使用时,会返回 true 和 false
POST my-index-000001/_doc/1?refresh
{
"is_published": true
}
POST my-index-000001/_doc/2?refresh
{
"is_published": false
}
GET my-index-000001/_search
{
"aggs": {
"publish_state": {
"terms": {
"field": "is_published"
}
}
},
"sort": [ "is_published" ],
"fields": [
{"field": "weight"}
],
"runtime_mappings": {
"weight": {
"type": "long",
"script": "emit(doc['is_published'].value ? 10 : 0)"
}
}
}
boolean 字段接受以下参数
doc_values- 是否应以列跨度(column-stride)方式将字段存储在磁盘上,以便以后用于排序、聚合或脚本编写?接受
true(默认)或false。 index- 该字段是否应支持快速搜索?接受
true(默认)和false。仅启用doc_values的字段仍然可以使用基于词条或范围的查询进行查询,尽管速度较慢。 ignore_malformed- 尝试将错误的数据类型索引到字段中默认会抛出异常,并拒绝整个文档。如果此参数设置为 true,则允许忽略该异常。格式错误的字段不会被索引,但文档中的其他字段会正常处理。接受
true或false。注意,如果使用了script参数,则不能设置此参数。 null_value- 接受上面列出的任何 true 或 false 值。该值用于替代任何显式的
null值。默认为null,这意味着该字段被视为缺失。注意,如果使用了script参数,则不能设置此参数。 on_script_error- 定义如果由
script参数定义的脚本在索引时抛出错误该怎么办。接受fail(默认,会导致整个文档被拒绝)和continue(会将字段注册到文档的_ignored元数据字段中并继续索引)。只有在同时设置了script字段时,才能设置此参数。 script- 如果设置了此参数,则该字段将索引由此脚本生成的值,而不是直接从源读取值。如果在输入文档的该字段上设置了值,则文档将被拒绝并返回错误。脚本的格式与其运行时对应项相同。
store- 是否应将字段值存储并可从
_source字段中独立检索。接受true或false(默认)。 meta- 关于该字段的元数据。
time_series_dimension-
(可选,布尔值)
将该字段标记为时间序列维度。默认为
false。index.mapping.dimension_fields.limit索引设置限制了索引中的维度数量。维度字段具有以下约束
doc_values和index映射参数必须为true。
boolean 字段在其默认配置中支持合成 _source。
合成源可能会对 boolean 字段值进行排序。例如
PUT idx
{
"settings": {
"index": {
"mapping": {
"source": {
"mode": "synthetic"
}
}
}
},
"mappings": {
"properties": {
"bool": { "type": "boolean" }
}
}
}
PUT idx/_doc/1
{
"bool": [true, false, true, false]
}
将变为
{
"bool": [false, false, true, true]
}