[英]Elasticsearch: retrieve only document _id where field doesn't exist
我想檢索字段“名稱”不存在的所有文檔 _id(沒有其他字段):
我知道我可以像這樣搜索不存在“名稱”字段的位置:
"query": {
"bool": {
"must_not": {
"exists": {
"field": "name"
}
}
}
}
而且我認為只獲取文檔的 _id 而不需要我需要使用的任何字段(如果我錯了請糾正我):
"fields": []
我如何結合這兩個部分來進行有效的查詢?
您可以只添加_source
並將其設置為 false,因為 Elasticsearch 默認會在該字段中返回整個 JSON object
"_source": false,
"query":{
...
}
這將僅從您指定的索引中檢索元數據,因此您的hits
數組將包含每個結果的_index
、 _type
、 _id
和_score
例如
{
"took" : 11,
"timed_out" : false,
"_shards" : {
"total" : 12,
"successful" : 12,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 20,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "filebeat-7.8.1-2021.01.28",
"_type" : "_doc"
"_id" : "SomeUniqeuId86aa",
"_score" : 1.0
},
{
"_index" : "filebeat-7.8.1-2021.01.28",
"_type" : "_doc"
"_id" : "An0therrUniqueiD",
"_score" : 1.0
}
]
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.