原英文版地址: https://www.elastic.co/guide/en/elasticsearch/reference/7.7/boolean.html, 原文档版权归 www.elastic.co 所有
本地英文版地址: ../en/boolean.html
本地英文版地址: ../en/boolean.html
重要: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 当前版本文档。
布尔字段接受JSON true和false值,但也可以接受被解释为 true 或 false 的字符串:
|
false 值 |
|
|
true 值 |
|
例如:
PUT my_index
{
"mappings": {
"properties": {
"is_published": {
"type": "boolean"
}
}
}
}
POST my_index/_doc/1
{
"is_published": "true"
}
GET my_index/_search
{
"query": {
"term": {
"is_published": true
}
}
}
像terms聚合这样的聚合使用1和0作为键,使用字符串"true"和"false"作为key_as_string。
布尔字段在脚本中使用时,返回1和0:
POST my_index/_doc/1
{
"is_published": true
}
POST my_index/_doc/2
{
"is_published": false
}
GET my_index/_search
{
"aggs": {
"publish_state": {
"terms": {
"field": "is_published"
}
}
},
"script_fields": {
"is_published": {
"script": {
"lang": "painless",
"source": "doc['is_published'].value"
}
}
}
}
boolean字段接受以下参数:
|
映射字段级查询时 提升(boost)。接受一个浮点数,默认值为 |
|
|
是否应该以列跨度(column-stride)的方式将字段存储在磁盘上,以便以后用于排序、聚合或编写脚本? 接受 |
|
|
字段是否可以搜索?接受 |
|
|
接受上面列出的任何 true 或 false 值。
该值将替换任何显式的 |
|
|
字段值是否应该与 |
|
|
与该字段有关的元信息。 |