Boolean datatype
editBoolean datatype
editBoolean fields accept JSON true
and false
values, but can also accept
strings and numbers which are interpreted as either true or false:
False values |
|
True values |
Anything that isn’t false. |
Deprecated in 5.1.0.
While Elasticsearch will currently accept the above values during index time. Searching a boolean field using these pseudo-boolean values is deprecated. Please use "true" or "false" instead.
Deprecated in 5.3.0.
Usage of any value other than false
, "false"
, true
and "true"
is deprecated.
For example:
PUT my_index { "mappings": { "my_type": { "properties": { "is_published": { "type": "boolean" } } } } } POST my_index/my_type/1 { "is_published": "true" } GET my_index/_search { "query": { "term": { "is_published": true } } }
Indexing a document with |
|
Searching for documents with a JSON |
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
:
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" } } } }
Parameters for boolean
fields
editThe following parameters are accepted by boolean
fields:
Mapping field-level query time boosting. Accepts a floating point number, defaults
to |
|
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 |
|
Should the field be searchable? Accepts |
|
Accepts any of the true or false values listed above. The value is
substituted for any explicit |
|
Whether the field value should be stored and retrievable separately from
the |