# Date Aggregation

**URL:** https://discuss.elastic.co/t/date-aggregation/40719
**Category:** Elasticsearch
**Created:** [February 2, 2016, 11:22am UTC](https://discuss.elastic.co/t/date-aggregation/40719 "2016-02-02T11:22:34Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sanju1323](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@sanju1323](https://discuss.elastic.co/u/sanju1323)
#### Post date: [February 2, 2016, 11:22am UTC](https://discuss.elastic.co/t/date-aggregation/40719/1 "2016-02-02T11:22:35Z")

</div>

Hi,

I have an index "sanjay" in which i'm sorting based on "OrderDate" (Sorting based on date) using java API. For Date wise sorting this is great.  
I'm using the following code to achieve the same.

```
MultiMatchQueryBuilder query = QueryBuilders.multiMatchQuery(field_name, Search_String);
SearchRequestBuilder req = client.prepareSearch("sanjay")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setSize(totalhits);

req.setQuery(query);

SearchResponse res = req.setFetchSource(new String[] { "field_name1", "field_name2" }, null).addSort("orderDate", SortOrder.ASC).execute().actionGet();

```

But, I want to sort based on Month in OrderDate and also I want to get only the first value in the Sorted Month.  
Is there any possiblity of achieving this???  
Please help

Thanks & Regards,  
Sanjay Reddy

---

<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: [July 5, 2017, 11:19pm UTC](https://discuss.elastic.co/t/date-aggregation/40719/2 "2017-07-05T23:19:43Z")

</div>


