gpt4 book ai didi

java - Elasticsearch Java High Level Client 7.3.1:聚合以搜索响应中的索引明智命中

转载 作者:行者123 更新时间:2023-12-03 02:14:22 27 4
gpt4 key购买 nike

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

关于java - Elasticsearch Java High Level Client 7.3.1:聚合以搜索响应中的索引明智命中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63899797/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com