elasticsearch java高级客户端7.3.1:搜索响应中按索引点击的聚合

gopyfrb3  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(1)|浏览(413)

我正在使用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);
yk9xbfzb

yk9xbfzb1#

我漏掉了一个下划线:(

sbb.aggreagation(AggregationBuilders.terms("index_wise_count").field("_index"));

相关问题