elasticSearch使用 exists 搜索过滤空内容

在存储时,如果数据不合法,全部改为 null。

在搜索时,对某个字段为空进行校验,如果该字段我为null,则过滤:

{
  "query": {
    "bool": {
      "must": {
        "exists": {
          "field": "字段名"
        }
      }
    }
  }
}

反之,取所有该字段为 null 的数据

{
  "query": {
    "bool": {
      "must_not": {
        "exists": {
          "field": "字段名"
        }
      }
    }
  }
}

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注