title: Aggregation date using Elasticsearch RestHighLevelClient
body: <p>I'm using Elasticsearch RestHighLevelClient and try to implement sql below: </p>
  
  <blockquote>
    <p>select format(date,'yyyy-MM-dd'), count(*) from order group by
    format(date,'yyyy-MM-dd')</p>
  </blockquote>
  
  <pre><code>    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();
  </code></pre>
  
  <p>I got the result but with many repeat date results like:</p>
  
  <pre><code>buckets:
    bucket1:
      key: 1583390009000
      keyAsString: 2020-03-05
      docCount: 4
    bucket2:  
      key: 1583391748000
      keyAsString: 2020-03-05
      docCount: 5
  </code></pre>
  
  <p>How should I avoid repeat date? I mean the same date(such as 2020-03-05) count as one bucket.</p>
  
  <p>Here’s some sample documents</p>
  
  <pre><code>  {
      "_index": "order_202003",
      "_type": "_doc",
      "_id": "1568274527051",
      "_score": 1,
      "_source": {
        "auto": 0,
        "collection_currency": "RMB",
        "collection_value": 0,
        "customerid": "",
        "freight": 0,
        "gs": 201101,
        "status": "accept",
        "time": "2020-03-05T10:01:23.000+0800"
      }
    },
    {
      "_index": "order_202003",
      "_type": "_doc",
      "_id": "1568274527078",
      "_score": 1,
      "_source": {
        "auto": 0,
        "collection_currency": "RMB",
        "collection_value": 0,
        "customerid": "",
        "freight": 0,
        "gs": 413572,
        "status": "accept",
        "time": "2020-03-05T17:29:53.000+0800"
      }
    }
  </code></pre>