ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
# Boolean 原文链接: [https://www.elastic.co/guide/en/elasticsearch/reference/5.4/boolean.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/boolean.html) 译文链接: [http://www.apache.wiki/pages/editpage.action?pageId=10031173](http://www.apache.wiki/pages/editpage.action?pageId=10031173) 贡献者: [张学](/display/~zhangxue),[ApacheCN](/display/~apachecn),[Apache中文网](/display/~apachechina) 布尔字段接受JSON **true**和**false**值,但也可以接受被解释为**true**或**false**的字符串和数字: | False值 | `false`, `"false"`, `"off"`, `"no"`, `"0"`, `""`, `0`, `0.0` | | True值 | 任何非false值 | **5.1.0中弃用。** 虽然Elasticsearch目前在索引时间内接受上述值。 不建议使用这些伪布尔值搜索布尔域。 请改用“**true**”或“**false**”。 **在5.3.0中弃用。** 任何非false,“false”,true和“true”的值已被弃用。 例如: ``` PUT my_index { "mappings": { "my_type": { "properties": { "is_published": { "type": "boolean" } } } } } POST my_index/my_type/1 { "is_published": "true" #1 } GET my_index/_search { "query": { "term": { "is_published": true #2 } } } ``` | 1 | Indexing a document with `"true"`, which is interpreted as `true`. | | 2 | Searching for documents with a JSON `true`. | 聚合类似 terms aggregation(术语聚合)使用1和0的键,以及**key_as_string**的字符串“**true**”和“**false**”。 在脚本中使用布尔字段,返回1和0: ``` POST my_index/my_type/1 { "is_published": true } POST my_index/my_type/2 { "is_published": false } GET my_index/_search { "aggs": { "publish_state": { "terms": { "field": "is_published" } } }, "script_fields": { "is_published": { "script": { "lang": "painless", "inline": "doc['is_published'].value" } } } } ``` ### Boolean字段的参数 **boolean**字段接受以下参数 | [`boost`](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/mapping-boost.html "boost") | 映射字段级查询时间提升。 接受一个浮点数,默认为**1.0**。 | | [`doc_values`](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/doc-values.html "doc_values") | 该字段是否应该以多列的方式存储在磁盘上,以便以后可以将其用于排序,聚合或脚本? 接受**true**(默认)或**false**。 | | [`index`](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/mapping-index.html "index") | 应该可以搜索该字段吗? **接受true(默认)和false。** | | [`null_value`](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/null-value.html "null_value") | 接受上面列出的任何真实或虚假的价值。 该值替换任何显式空值。 默认为**null**,这意味着该字段被视为丢失。 | | [`store`](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/mapping-store.html "store") | 字段值是否应与**_sourcefield**分开存储和检索。 接受**true**或**false**(默认)。 |