Elasticsearch Exists query – 存在查询

这种查询返回包含字段索引值的文档。简单的来说,就是查询文档中是否包含field指定的字段;
这个查询只有一个参数,field:要搜索的字段的名词

  1. 如果为null[],会触发异常,parsing_exception: [exists] unknown token [VALUE_NULL] after [field]
  2. 如果为"",会触发异常,illegal_argument_exception

查找缺少字段索引值的文档,可以使用bool查询中的must_not。

请求示例

GET blak_new/_search
{
    "query": {
        "bool": {
          "must_not": {
            "exists": {
            "field": "address"
            }
          }
        }
    }
}

返回结果

{
  "took" : 12,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.0,
    "hits" : [
      {
        "_index" : "blak_new",
        "_type" : "_doc",
        "_id" : "1009",
        "_score" : 0.0,
        "_source" : {
          "account_number" : 164,
          "balance" : 9101,
          "firstname" : "Cummings",
          "lastname" : "Holt",
          "age" : 26,
          "gender" : "F",
          "employer" : "Comtrak",
          "email" : "[email protected]",
          "city" : "Chaparrito",
          "state" : "WI"
        }
      }
    ]
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章