创建测试数据
PUT test/_bulk
{"create":{"_index":"test","_type":"type1","_id":"1"}}
{"title":"","id":1}
{"create":{"_index":"test","_type":"type1","_id":"2"}}
{"title":null,"id":2}
{"create":{"_index":"test","_type":"type1","_id":"3"}}
{"title":"liab","id":3}
给title添加"fielddata": true属性,保证text类型的字段可以进行script查询方式
PUT test/_mapping/type1
{
"type1": {
"properties": {
"title": {
"type": "text",
"fielddata": true
}
}
}
}
查看全部文档
GET test/_search
查看title字段值不为NULL的
GET test/_search
{
"query": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"exists": {
"field": "title"
}
}
]
}
}
]
}
}
}
查看title字段值为NULL的
GET test/_search
{
"query": {
"bool": {
"must": [
{
"bool": {
"must_not": [
{
"exists": {
"field": "title"
}
}
]
}
}
]
}
}
}
查看title不为NULL,不为""空字符串的
GET test/_search
{
"query": {
"wildcard": {
"title": {
"value": "*"
}
}
}
}
查看title字段为NULL的,为""空字符串的
GET test/_search
{
"query": {
"script": {
"script": "doc['title'].length == 0"
}
}
}