elasticsearch 搜索空字符串、NULL值

创建测试数据

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

elasticsearch 搜索空字符串、NULL值_第1张图片

查看title字段值不为NULL的

GET test/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "must": [
              {
                "exists": {
                  "field": "title"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

elasticsearch 搜索空字符串、NULL值_第2张图片

查看title字段值为NULL的

GET test/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "must_not": [
              {
                "exists": {
                  "field": "title"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

elasticsearch 搜索空字符串、NULL值_第3张图片

查看title不为NULL,不为""空字符串的

GET test/_search
{
  "query": {
    "wildcard": {
      "title": {
        "value": "*"
      }
    }
  }
}

elasticsearch 搜索空字符串、NULL值_第4张图片

查看title字段为NULL的,为""空字符串的

GET test/_search
{
  "query": {
    "script": {
      "script": "doc['title'].length == 0"
    }
  }
}

elasticsearch 搜索空字符串、NULL值_第5张图片

你可能感兴趣的:(kibana,elasticsearch)