表格如下:
想要獲得所有測站最新的一條數(shù)據(jù),即先對Station分組,根據(jù)time進行排序(降序),取第一條。
GET test/_search
{"query":{"bool":{"must":[{"match_all":{}}]}},"size":0,"aggs":{"stationAgg":{"terms":{"field":"Station","size":100,"min_doc_count":1},"aggs":{"top1":{"top_hits":{"size":1,"sort":[{"time":{"order":"desc"}}]}}}}}}
參考文章:文章來源:http://www.zghlxwxcb.cn/news/detail-606410.html
分組后進行排序取第一條,然后再過濾 - Elastic 中文社區(qū)文章來源地址http://www.zghlxwxcb.cn/news/detail-606410.html
到了這里,關(guān)于【ES】分組后每組取第一條的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!