我想要得到幾年並應用羣組來獲取記錄的計數。因爲我這個SQL查詢是 -通過sql查詢創建正義查詢
select substr(lastModified,0,4) , count(*) from EOM group by substr(lastModified,0,4).
我創建查詢以上 -
{
"size":0,
"aggs": {
"profit": {
"scripted_metric": {
"init_script" : "_agg.transactions = []",
"map_script" : "_agg.transactions.add(doc.timeModified.date.getYear())",
"combine_script" : "return _agg.transactions"
}
},
"aggs":{
"terms":{
"field":"profit"
}
}
}
}
結果 -
{
"aggregations": {
"profit": {
"value": [
[
2014,
2015,
2016,
2015,
2017
],
[
2015,
2015,
2016,
2016,
2017
]
]
},
"aggs": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
}
它給了我多年,但沒有利潤申請aggrgation和它的桶是空白的。
我想爲上述sql查詢進行有意義的查詢。
什麼是你在上面張貼的查詢輸出/錯誤? –
@TimBiegeleisen發佈更新! –
發佈更新!!!!!! –