过滤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": "*"
      }
    }
  }
}
原文地址:https://www.cnblogs.com/wslook/p/14210225.html