好的想法是十分钱一打,真正无价的是能够实现这些想法的人。

如何实现自定义排序,分别对不同字段进行不同的排序

Elasticsearch | 作者 202xxx | 发布于2021年08月11日 | 阅读数:826

如何对is_top=1的数据进行pub_time降序,对is_top=0的数据进行update_time降序,并且对所有数据进行is_top降序排序?
is_top = [0, 0, 0, 1, 1, 1, 1]
update_time = [2, 3, 4, 6, 3, 7, 8]
pub_time= [6, 3, 7, 8, 2, 3, 4]
 
或者说把这段SQL怎么转换成ES的DSL?
SELECT * from table_a a where a.pub_time BETWEEN (now()-interval 90 day) and now()
order by is_top desc,case when is_top = 1 then update_time else pub_time end desc
已邀请:

tongchuan1992 - 学无止境、学以致用

赞同来自:

你这个分成三个语句进行各自查询不就可以了吗

Hao_Lee

赞同来自:

存一个组合字段sort,按照这个字段排序(假设pub_time和update_time都是10位数的时间戳)
if (is_top == 1):
sort = 1*10000000000 + update_time
else:
sort = pub_time

HelloClyde

赞同来自:

还是用script打分吧

要回复问题请先登录注册