我想检索所有不存在字段“名称”的文档_id(不包含其他字段):
我知道我可以搜索不存在“名称”字段的地方,如下所示:
"query": {
"bool": {
"must_not": {
"exists": {
"field": "name"
}
}
}
}
而且我认为仅在没有任何我需要使用的字段的情况下获取文档的_id(如果我错了,请更正我):
"fields": []
如何将这两个部分结合起来进行有效的查询?
您可以添加_source
并设置为false,因为默认情况下Elasticsearch将在该字段中返回整个JSON对象
"_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
}
]
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句