# Perform count with high-level-rest-client ans spring boot

**URL:** <https://discuss.elastic.co/t/perform-count-with-high-level-rest-client-ans-spring-boot/221150>\
**Category:** Elasticsearch\
**Created:** [February 27, 2020, 6:28am UTC](https://discuss.elastic.co/t/perform-count-with-high-level-rest-client-ans-spring-boot/221150 "2020-02-27T06:28:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RAHULRAJSONU](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahulrajsonu/32/63398_2.png) [@RAHULRAJSONU](https://discuss.elastic.co/u/RAHULRAJSONU)\
**Post date:** [February 27, 2020, 6:28am UTC](https://discuss.elastic.co/t/perform-count-with-high-level-rest-client-ans-spring-boot/221150/1 "2020-02-27T06:28:55Z")

</div>

I am trying to get the count of total documents with some filtration.

here what I am trying-

```
    public Object count() throws IOException {
          SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
          BoolQueryBuilder query = QueryBuilders.boolQuery()
                .must(QueryBuilders.matchQuery("job_name", "AGGREGRATION_TABLE"))
                .must(QueryBuilders.rangeQuery("start_time").gte("now-10d").lte("now"));
          sourceBuilder.query(query);
          SearchRequest searchRequest = new SearchRequest();
          searchRequest.indices(INDEX);
          searchRequest.source(sourceBuilder);
          SearchResponse response = restHighLevelClient.search(searchRequest, 
                RequestOptions.DEFAULT);
          return response.getHits().totalHits;
   }

```

I am always getting the count as 0,  
But when I am trying to hit the elastic API via postman with following details,

```
GET /eps/_count
{
  "query" : {
    "bool" : {
      "filter" : {
        "range" : {
          "start_time" : { 
            "gt" : "now-10d" 
          }
        }
      },
  "must" : {
    "match" : {
      "job_name" : "AGGREGRATION_TABLE"
    }
  }
  }
  }
} 

```

I am getting the correct result as

```
{
    "count": 3,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    }
}

```

Any help would be appreciated.  
thank you.

---

<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:** [March 26, 2020, 6:29am UTC](https://discuss.elastic.co/t/perform-count-with-high-level-rest-client-ans-spring-boot/221150/2 "2020-03-26T06:29:08Z")

</div>

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