# Elastic Search High Level Client Aggregation to get Index wise Hits on Alias Search

**URL:** https://discuss.elastic.co/t/elastic-search-high-level-client-aggregation-to-get-index-wise-hits-on-alias-search/248994
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [September 17, 2020, 2:26pm UTC](https://discuss.elastic.co/t/elastic-search-high-level-client-aggregation-to-get-index-wise-hits-on-alias-search/248994 "2020-09-17T14:26:47Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![hackerzpark](https://avatars.discourse-cdn.com/v4/letter/h/a587f6/32.png) [@hackerzpark](https://discuss.elastic.co/u/hackerzpark)
#### Post date: [September 17, 2020, 2:26pm UTC](https://discuss.elastic.co/t/elastic-search-high-level-client-aggregation-to-get-index-wise-hits-on-alias-search/248994/1 "2020-09-17T14:26:47Z")

</div>

Hi, 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);

```

Can some 1 help how to implement aggregation to get index wise hit counts for alias?

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [September 17, 2020, 3:21pm UTC](https://discuss.elastic.co/t/elastic-search-high-level-client-aggregation-to-get-index-wise-hits-on-alias-search/248994/2 "2020-09-17T15:21:14Z")

</div>

There is a missing underscore in the `field("index")` statement, compared to your query.

---

<div class="post-metadata">

### Author: ![hackerzpark](https://avatars.discourse-cdn.com/v4/letter/h/a587f6/32.png) [@hackerzpark](https://discuss.elastic.co/u/hackerzpark)
#### Post date: [September 17, 2020, 3:52pm UTC](https://discuss.elastic.co/t/elastic-search-high-level-client-aggregation-to-get-index-wise-hits-on-alias-search/248994/3 "2020-09-17T15:52:27Z")

</div>

Thanks

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 15, 2020, 3:52pm UTC](https://discuss.elastic.co/t/elastic-search-high-level-client-aggregation-to-get-index-wise-hits-on-alias-search/248994/4 "2020-10-15T15:52:28Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
