Elasticsearch 查询结果排序不一致问题

1. ES排序问题

  • 场景: 查询ES时,两次访问查询的主备分片不同,且没有评分,返回的数据顺序不一致
    官方解释如下:

when two documents have the same score, they will be sorted by their internal Lucene doc id (which is unrelated to the _id) by default. However these doc ids could be different across copies of the same shard.

  • 解决方案如下:

The recommended way to work around this issue is to use a string that identifies the user that is logged is (a user id or session id for instance) as a preference This ensures that all queries of a given user are always going to hit the same shards, so scores remain more consistent across queries.

preference

参数
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Elasticsearch中,排序问题可能出现在聚合操作中。根据引用的描述,Elasticsearch排序操作时,会先对每个分片进行排序,然后将每个分片的前17名结果进行再次聚合和排序,最终返回排序后的前5条记录作为结果。这个排序策略来源于官方给出的算式,根据算式,如果请求只发往一个分片,就返回前5条记录;如果请求发送给多个分片,每个分片返回的记录数是5 * 1.5 = 17。这个策略可能导致在返回的数据中,实际的排序结果与期望的排序结果不一致。 因此,如果你在Elasticsearch中遇到排序问题,可以检查是否涉及到了多个分片,并且了解Elasticsearch排序策略。你可以参考引用提供的链接来了解更多关于Elasticsearch排序操作的详细信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Elasticsearch聚合学习之五:排序结果不准的问题分析](https://blog.csdn.net/boling_cavalry/article/details/90319399)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [3. elasticsearch 汇总排序问题剖析](https://blog.csdn.net/wangzhiqiang123456/article/details/123073114)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值