[英]Elasticsearch. Get count of values in a field of specific index
这将为您提供人员索引中某个字段的编号(如果该字段存在于所有文档中,则将与索引中的文档数量相同):
const getFieldCount = (field) => client.search({
size: 0,
index: 'persons',
body: {
query: { match_all: {} },
aggs: {
field_count: {
value_count: {
field,
},
},
},
},
});
getFieldCount('dri')
.then((res) => console.log(res));
按照上面的示例,以Tarek的答案为起点,我研究了此主体查询,该查询恰好返回了我需要的内容:精确字段中的值计数。
const getFieldCount = (field) => client.count({
index: 'institutions',
body: {
query: {
bool: {
must:[
{ "exists": {"field": "library_type_id"} }
],
},
},
},
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.