我想在彈性搜索查詢的日期字段上應用group by子句。這是我的代碼。Elasticsearch中的聚合
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();
但查詢不返回預期結果。顯示
結果如下
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
我在elasticsearch新的,不知道我錯過了什麼。 任何幫助,非常感謝!
你的查詢是怎樣的? – Kulasangar
我有查詢SQL ----從tableName中選擇不同的(SSTATUS),計數(SSTATUS),TO_DATE(dtcreated,'DD.MON.YYYY') Where SSTATUS LIKE'CANCELED' group by TO_DATE(dtcreated, 'DD.MON.YYYY'),sstatus order by SSTATUS – Aniket
你是如何在java中查詢它的?你直接在你的代碼中使用SQL查詢? – Kulasangar