Date Histogram

Hi,

I'm facing a problem while fetching data from Elasticsearch using Java API.
Please have a look at the following index.

From the above index, I need year wise aggregation of the data.
I'm using the following code to achieve that.

BoolQueryBuilder query = new BoolQueryBuilder();
query.must(QueryBuilders.termsQuery("customerId", customerIds));
query.must(QueryBuilders.termsQuery("productId", productIds));
SearchRequestBuilder req = con.getClient().prepareSearch("investigation_info_idx").setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setQuery(query);
req.setFetchSource(new String[] { "customerId", "productId", "testResult", "orderDate" }, null)
.addSort("orderDate", SortOrder.ASC).addAggregation(AggregationBuilders.dateHistogram("dateagg").field("orderDate").interval(DateHistogram.Interval.YEAR));
SearchResponse res = req.execute().actionGet();

for every year in OrderDate, I need only the first result of that year as I have selected Interval as Year.
In this index, I'm expecting the result for testResult as 102,93,77 having orderDates ( 2010-04-20T18:30:00.000Z, 2011-04-22T18:30:00.000Z, 2012-04-24T18:30:00.000Z) respectively.

But I'm getting all the testResult values. Please correct me if I'm doing anything wrong in the code.
Please help me in getting out of this issue.

Thanks & Regards,
Sanjay Reddy

Can anyone please help me in this issue