I am using ES 7.3.1 and Elasticsearch high level client 7.3.1 We have an alias which comprises of 3 indexes.
Alias Name : employee_search
Indexes in this alias : contract_employee,permanent_employee,client
I am searching over this alias as
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);
In response I need an aggregation where I can get index wise hits (which index gave how many hits?) Aggregation which needs to be implemented is
{
"aggs": {
"index_wise_count": {
"terms": {
"field": "_index"
}
}
}
}
How can I implement this in the existing search response?
What I tried but did not work:
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"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.