作家排行榜topN

阅读: 评论:0

作家排行榜topN

作家排行榜topN

背景:对于一个小说网站,我们要将作家的受欢迎程度进行一个排序
1.对于mysql中:
表结构:

其中clickcount是该本书被点击的总次数
把作家的所有作品总点击数加起来求和再进行排序

select sum(a.clickcount) countTotal,a.author,group_concat(a.name) novels_name
from vel a
where 1=1 group by author order by countTotal desc

group_concat:将字段进行拼接,并且以一行的形式返回
结果:

2.在es中实现:
我们的思路是一样的,我们就将sql语句转换为es的语法
把sql语句转换为es语句网址: /

但是在一行不好看。
所以可以用到格式化es语句网址:

进入kibana
1.创建作家排行的索引
PUT novel_author_countsort
{
“mappings” : {
“doc” : {
“properties” : {
“@timestamp” : {
“type” : “date”
},
“@version” : {
“type” : “text”,
“fields” : {
“keyword” : {
“type” : “keyword”,
“ignore_above” : 256
}
}
},
“author” : {
“type” : “keyword”
},
“category” : {
“type” : “keyword”
},
“clickcount” : {
“type” : “long”
},
“collect” : {
“type” : “long”
},
“count” : {
“type” : “long”
},
“countrecommend” : {
“type” : “long”
},
“detail” : {
“type” : “text”,
“fields” : {
“keyword” : {
“type” : “keyword”,
“ignore_above” : 256
}
}
},
“detaul” : {
“type” : “text”,
“fields” : {
“keyword” : {
“type” : “keyword”,
“ignore_above” : 256
}
}
},
“id” : {
“type” : “long”
},
“lastchapter” : {
“type” : “text”,
“fields” : {
“keyword” : {
“type” : “keyword”,
“ignore_above” : 256
}
}
},
“lastupdate” : {
“type” : “date”,
“format” : “yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis”
},
“monthclick” : {
“type” : “long”
},
“monthrecommend” : {
“type” : “long”
},
“name” : {
“type” : “keyword”
},
“new” : {
“type” : “text”,
“fields” : {
“keyword” : {
“type” : “keyword”,
“ignore_above” : 256
}
}
},
“novelinfo” : {
“type” : “keyword”
},
“picurl” : {
“type” : “text”,
“fields” : {
“keyword” : {
“type” : “keyword”,
“ignore_above” : 256
}
}
},
“status” : {
“type” : “text”,
“fields” : {
“keyword” : {
“type” : “keyword”,
“ignore_above” : 256
}
}
},
“weekclick” : {
“type” : “long”
},
“weekrecommend” : {
“type” : “long”
}
}
}
}
}
将author字段类型改为keyword

2.给索引加载数据
POST _reindex
{
“source”: {
“index”: “novel_new”
},
“dest”: {
“index”: “novel_author_countsort”
}
}
3.测试,将之前转行后的内容直接cv过来
GET novel_author_countsort/_search
{
“size” : 0,
“aggs”: {
“author”: {
“terms”: {
“field”: “author”,
“size”: 10,
“order”: {
“countTotal”: “DESC”
}
},
“aggs”: {
“countTotal”: {
“sum”: {
“field”: “clickcount”
}
},
“top”: {
“top_hits”: {
“size”: 1
}
}
}
}
}
}
4.查看结果

可以看到作者:危险的世界 countTotal:3339494 排名第一

与数据库中内容一致

本文发布于:2024-01-28 21:51:27,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170644989010525.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:作家   排行榜   topN
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23