I want to apply group by clause on date field for elasticsearch query. This is my code.
SearchRequestBuilder srb = client
.prepareSearch(ConstantsValue.indexName)
.setTypes(ConstantsValue._Type)
.addAggregation(
AggregationBuilders
.dateHistogram("aggs")
.field("DTCREATED")
.interval(Interval.MONTH)
.format("yyyy-MM-dd")
.preZone("+05:30")
.preZoneAdjustLargeInterval(true)
.minDocCount(1)
)
.setSize(Integer.MAX_VALUE)
.setQuery(query);
SearchResponse response = srb
.setSearchType(SearchType.QUERY_AND_FETCH)
.setFetchSource(ConstantsValue.fieldList, null)
.execute()
.actionGet();
But query does not return expected result.
Result displayed is as follows
Value :{"DTCREATED":"2016-09-29T18:30:00.000Z"}
Key :AVfdaeSC3n3Bn-RaoFgg
Value :{"DTCREATED":"2016-09-29T18:30:00.000Z"}
Key :AVfdaeSC3n3Bn-RaoFgl
Value :{"DTCREATED":"2016-09-29T18:30:00.000Z"}
Key :AVfdaeSC3n3Bn-RaoFgq
Value :{"DTCREATED":"2016-08-31T18:30:00.000Z"}
Key :AVfdaeSC3n3Bn-RaoFgv
Value :{"DTCREATED":"2016-09-06T18:30:00.000Z"}
Key :AVfdaeSC3n3Bn-RaoFg0
Value :{"DTCREATED":"2016-09-22T18:30:00.000Z"}
Key :AVfdaeSC3n3Bn-RaoFg5
Value :{"DTCREATED":"2016-09-22T18:30:00.000Z"}
Key :AVfdaeSC3n3Bn-RaoFhA
Value :{"DTCREATED":"2016-09-12T18:30:00.000Z"}
Key :AVfdaeSC3n3Bn-RaoFhF
I am new in elasticsearch and don't know what I am missing. Any help is greatly appreciated!