本文主要介绍一下关于ES的boolean类型,希望对大家理解和使用ES有帮助。
Boolea n Field是接受JSON true或者false的值,也接受可以被转为true或者false的字符串
例子:
curl -X PUT "localhost:9200/my-index-000001?pretty" -H 'Content-Type: application/json' -d'
{
"mappings": {
"properties": {
"is_published": {
"type": "boolean"
}
}
}
}
'curl -X POST "localhost:9200/my-index-000001/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
"is_published": "true"
}
'curl -X GET "localhost:9200/my-index-000001/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"term": {
"is_published": true
}
}
}
'通过上面的例子可以看出,创建了一个名为my-index-000001的文档,映射关系中有一个type为boolean的field为is_published。
下面是一个term查询,匹配is_published为true的文档。
curl -X POST "localhost:9200/my-index-000001/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
"is_published": true
}
'curl -X POST "localhost:9200/my-index-000001/_doc/2?pretty" -H 'Content-Type: application/json' -d'
{
"is_published": false
}
'curl -X GET "localhost:9200/my-index-000001/_search?pretty" -H 'Content-Type: application/json' -d'
{
"aggs": {
"publish_state": {
"terms": {
"field": "is_published"
}
}
},
"script_fields": {
"is_published": {
"script": {
"lang": "painless",
"source": "doc[\u0027is_published\u0027].value"
}
}
}
}
'下面是所列的参数列表是boolean field所接受的: