Boolean field type

Boolean fields accept JSON true and false values, but can also accept strings which are interpreted as either true or false:

False values

false, “false”, “” (empty string)

True values

true, “true”

For example:

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

Indexing a document with “true”, which is interpreted as true.

Searching for documents with a JSON true.

Aggregations like the terms aggregation use 1 and 0 for the key, and the strings "true" and "false" for the key_as_string. Boolean fields when used in scripts, return 1 and 0:

  1. POST my-index-000001/_doc/1
  2. {
  3. "is_published": true
  4. }
  5. POST my-index-000001/_doc/2
  6. {
  7. "is_published": false
  8. }
  9. GET my-index-000001/_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. "source": "doc['is_published'].value"
  23. }
  24. }
  25. }
  26. }

Parameters for boolean fields

The following parameters are accepted by boolean fields:

boost

Mapping field-level query time boosting. Accepts a floating point number, defaults to 1.0.

doc_values

Should the field be stored on disk in a column-stride fashion, so that it can later be used for sorting, aggregations, or scripting? Accepts true (default) or false.

index

Should the field be searchable? Accepts true (default) and false.

null_value

Accepts any of the true or false values listed above. The value is substituted for any explicit null values. Defaults to null, which means the field is treated as missing.

store

Whether the field value should be stored and retrievable separately from the _source field. Accepts true or false (default).

meta

Metadata about the field.