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"
        }
      }
    ]
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章