Boolean

原文链接:

https://www.elastic.co/guide/en/elasticsearch/reference/5.4/boolean.html

译文链接:

http://www.apache.wiki/pages/editpage.action?pageId=10031173

贡献者:

张学ApacheCNApache中文网

布尔字段接受JSON truefalse值,但也可以接受被解释为truefalse的字符串和数字:

| False值 | false, "false", "off", "no", "0", "", 0, 0.0 | | True值 | 任何非false值 |

5.1.0中弃用。 虽然Elasticsearch目前在索引时间内接受上述值。 不建议使用这些伪布尔值搜索布尔域。 请改用“true”或“false”。

在5.3.0中弃用。 任何非false,“false”,true和“true”的值已被弃用。

例如:

  1. PUT my_index
  2. {
  3. "mappings": {
  4. "my_type": {
  5. "properties": {
  6. "is_published": {
  7. "type": "boolean"
  8. }
  9. }
  10. }
  11. }
  12. }
  13. POST my_index/my_type/1
  14. {
  15. "is_published": "true" #1
  16. }
  17. GET my_index/_search
  18. {
  19. "query": {
  20. "term": {
  21. "is_published": true #2
  22. }
  23. }
  24. }

| 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:

  1. POST my_index/my_type/1
  2. {
  3. "is_published": true
  4. }
  5. POST my_index/my_type/2
  6. {
  7. "is_published": false
  8. }
  9. GET my_index/_search
  10. {
  11. "aggs": {
  12. "publish_state": {
  13. "terms": {
  14. "field": "is_published"
  15. }
  16. }
  17. },
  18. "script_fields": {
  19. "is_published": {
  20. "script": {
  21. "lang": "painless",
  22. "inline": "doc['is_published'].value"
  23. }
  24. }
  25. }
  26. }

Boolean字段的参数

boolean字段接受以下参数

| boost | 映射字段级查询时间提升。 接受一个浮点数,默认为1.0。 | | doc_values | 该字段是否应该以多列的方式存储在磁盘上,以便以后可以将其用于排序,聚合或脚本? 接受true(默认)或false。 | | index | 应该可以搜索该字段吗? 接受true(默认)和false。 | | null_value | 接受上面列出的任何真实或虚假的价值。 该值替换任何显式空值。 默认为null,这意味着该字段被视为丢失。 | | store | 字段值是否应与_sourcefield分开存储和检索。 接受truefalse(默认)。 |