如何筛选帖子评论赞同数量最高的那条数据?

2018-03-30 16:54:46 +08:00
 klakekent
es 里面每条数据结构如下

postid,commentid,comment,starts
1 1 ×××× 3
1 2 ×××× 4
2 3 ×××× 1
2 4 ×××× 0


我想选出来每一个帖子下面的评论 starts 最高的一条该怎么做呢?
3069 次点击
所在节点    Elasticsearch
6 条回复
klakekent
2018-03-30 16:56:40 +08:00
我想得到的结果大概就是
1 2 ××× 4
2 3 ××× 1
zhangfeiwudi
2018-03-30 17:00:33 +08:00
group on + order by 可行否?
klakekent
2018-03-30 18:01:50 +08:00
我发现用 aggs 和 top_hits 组合会有个问题,就是比如我的 postid 有 6 条评论,但是通过这个方式选出来显示 total 数量不足 6 条
turan12
2018-03-30 22:31:50 +08:00
max(stars) + group by postid
Hieast
2018-03-31 01:41:55 +08:00
使用 terms postid 桶,每个桶里取 max starts
klakekent
2018-06-03 13:38:09 +08:00
解决 用 collapse 很简单

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/442911

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX