[英]Elasticsearch: retrieve only document _id where field doesn't exist
I would like to retrieve all document _ids (without other fields) where field "name" doesn't exist:我想检索字段“名称”不存在的所有文档 _id(没有其他字段):
I know I can search for where field "name" doesn't exist like this:我知道我可以像这样搜索不存在“名称”字段的位置:
"query": {
"bool": {
"must_not": {
"exists": {
"field": "name"
}
}
}
}
and I think that to get the _id of the document only without any fields i need to use (correct me if I'm wrong):而且我认为只获取文档的 _id 而不需要我需要使用的任何字段(如果我错了请纠正我):
"fields": []
How do I combine these 2 parts to make a query that works?我如何结合这两个部分来进行有效的查询?
You can just add _source
and set to false as Elasticsearch will return the entire JSON object in that field by default您可以只添加_source
并将其设置为 false,因为 Elasticsearch 默认会在该字段中返回整个 JSON object
"_source": false,
"query":{
...
}
and this will retrieve just the metadata from your specified index, so your hits
array will contain _index
, _type
, _id
and _score
for each result这将仅从您指定的索引中检索元数据,因此您的hits
数组将包含每个结果的_index
、 _type
、 _id
和_score
eg例如
{
"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.