# Aggregation date using RestHighLevelClient

**URL:** <https://discuss.elastic.co/t/aggregation-date-using-resthighlevelclient/223871>\
**Category:** Elasticsearch\
**Created:** [March 17, 2020, 8:06am UTC](https://discuss.elastic.co/t/aggregation-date-using-resthighlevelclient/223871 "2020-03-17T08:06:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhonghuafy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zhonghuafy/32/64488_2.png) [@zhonghuafy](https://discuss.elastic.co/u/zhonghuafy)\
**Post date:** [March 17, 2020, 8:06am UTC](https://discuss.elastic.co/t/aggregation-date-using-resthighlevelclient/223871/1 "2020-03-17T08:06:06Z")

</div>

I'm trying to implement sql below:  
`select format(date,'yyyy-MM-dd'), count(*) group by format(date,'yyyy-MM-dd')`  
using RestHighLevelClient  
java code:

```auto
    SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
    sourceBuilder.query(QueryBuilders.matchAllQuery());
    sourceBuilder.aggregation(AggregationBuilders.terms("date_count").field("time").format("yyyy-MM-dd"));
    SearchRequest searchRequest = new SearchRequest("order_*");
    searchRequest.source(sourceBuilder);
    SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
    Aggregations aggregations = searchResponse.getAggregations();

```

I got the result but with many repeat date results as images shows below:

 ![{B140B0D7-EA44-40D3-BA65-AC88CFA0F11E}_20200317160043](https://us1.discourse-cdn.com/elastic/original/3X/c/2/c2b12b5ca0b18e6479c7441c1fbcf0578c27dc70.jpeg)

How should I avoid repeat date? I mean the same date(such as 2020-03-05) count as one row.

---

<div class="post-metadata">

**Author:** ![zhonghuafy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zhonghuafy/32/64488_2.png) [@zhonghuafy](https://discuss.elastic.co/u/zhonghuafy)\
**Post date:** [March 18, 2020, 5:26am UTC](https://discuss.elastic.co/t/aggregation-date-using-resthighlevelclient/223871/2 "2020-03-18T05:26:14Z")

</div>

I've found my answer:

> <https://stackoverflow.com/questions/60718650/aggregation-date-using-elasticsearch-resthighlevelclient>

---

<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:** [April 15, 2020, 5:26am UTC](https://discuss.elastic.co/t/aggregation-date-using-resthighlevelclient/223871/3 "2020-04-15T05:26:17Z")

</div>

Closed on April 15, 2020, 5:26am UTC

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