我正在使用ES 7.3.1和Elasticsearch高级客户端7.3.1
我们有一个包含3个索引的别名。
Alias Name : employee_search
Indexes in this alias : contract_employee,permanent_employee,client
我正在搜索这个别名SearchRequest searchReq = new SearchRequest("employee_search");
WrapperQueryBuilder qb = QueryBuilders.wrapperQuery(searchQuery); //i am preparing a dsl query
SearchSourceBuilder sbb = new SearchSourceBuilder();
sbb.query(qb);
searchReq.source(sbb);
SearchResponse resp = esClient.search(searchReq, RequestOptions.DEFAULT);
作为响应,我需要一个聚合,在这里我可以获取明智的索引匹配(哪个索引提供了多少匹配?)需要实现的汇总是
{
"aggs": {
"index_wise_count": {
"terms": {
"field": "_index"
}
}
}
}
如何在现有的搜索响应中实现这一点?我试过但没用的方法:
SearchRequest searchReq = new SearchRequest("employee_search");
WrapperQueryBuilder qb = QueryBuilders.wrapperQuery(searchQuery); //i am preparing a dsl query
SearchSourceBuilder sbb = new SearchSourceBuilder();
sbb.query(qb);
sbb.aggreagation(AggregationBuilders.terms("index_wise_count").field("index"));
searchReq.source(sbb);
SearchResponse resp = esClient.search(searchReq, RequestOptions.DEFAULT);
最佳答案
我错过了一个下划线:(
sbb.aggreagation(AggregationBuilders.terms("index_wise_count").field("_index"));