布尔型字段类型
布尔型字段接受 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
聚合之类的聚合使用 1
和 0
作为 key
,使用字符串 "true"
和 "false"
作为 key_as_string
。布尔型字段在脚本中使用时,返回 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
- 字段是否应以列步长方式存储在磁盘上,以便后续可用于排序、聚合或脚本编写?接受
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
。
重要提示
合成 _source
仅对 TSDB 索引(将 index.mode
设置为 time_series
的索引)普遍可用 (Generally Available)。对于其他索引,合成 _source
处于技术预览 (technical preview) 阶段。技术预览中的功能可能会在未来版本中更改或删除。Elastic 将努力修复任何问题,但技术预览中的功能不受官方 GA 功能的支持 SLA 的约束。
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]
}