试图找到任何方法来检索特定字段中值的计数。但是到目前为止,我在Elastic API文档中找不到合适的方法。
让我们考虑一下我有以下基本代码:
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});
我需要从索引“人”,字段“dri”中获取计数
最佳答案
这将使您获得人员索引中某个字段的编号(如果该字段存在于所有文档中,则将与索引中的文档数量相同):
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));
关于elasticsearch - Elasticsearch。获取特定索引字段中的值计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52786114/