[英]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.