首页/数据/NoSQL 速查/exists 字段存在性查询
Elasticsearch89 条

exists 字段存在性查询

exists 匹配字段存在且至少有一个非空值的文档:字段缺省、JSON null 与空数组都不算存在;常与 must_not 组合查找缺失数据。

NoSQL 速查数据更新于 2026-10-12
接口{ "exists": { "field": "user" } }
不匹配的情况字段未写入、值为 null、数组为空
组合用法must_not + exists 查出缺字段的文档,便于补数据

示例

示例
GET /my-index/_search
{
  "query": {
    "bool": {
      "must_not": [ { "exists": { "field": "email" } } ]
    }
  }
}
object 类型的父字段只要有子字段写入就算存在;查 nested 字段存在性要放进 nested 查询里。

易错点

  • 写入空字符串不等于 null,exists 仍会命中,数据清洗时要统一约定
  • 必须依赖 _source 回补数据时先确认索引没有关闭 _source

数据来源与参考

  • Elasticsearch Guide: Exists query
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌