过滤text字段为空的数据

一、概述

  有两种可行方案,如下:

  1. 使用exists过滤为null或无此字段的文档;使用精确查询过滤空字符串
  2. 使用wildcard通配符模糊查询

二、方案一:exists

GET /news/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "exists": {
            "field": "url"
          }
        }
      ],
      "must_not": [
        {
          "term": {
            "url": ""
          }
        }
      ]
    }
  }
}

三、方案二:wildcard通配符(性能很差)

GET /news/_search
{
  "query": {
    "wildcard":{
      "text": {
        "value": "*"
      }
    }
  }
}

 

posted @ 2020-12-30 10:49  时间-海  阅读(264)  评论(0编辑  收藏  举报