elasticsearch学习笔记(三十三)——Elasticsearch Bouncing Results问题
想象一下有两个文档有同样值的时间戳字段搜索结果用 timestamp 字段来排序。 由于搜索请求是在所有有效的分片副本间轮询的那就有可能发生主分片处理请求时这两个文档是一种顺序 而副本分片处理请求时又是另一种顺序。这就是所谓的 bouncing results 问题: 每次用户刷新页面搜索结果表现是不同的顺序。 让同一个用户始终使用同一个分片这样可以避免这种问题 可以设置 preference 参数为一个特定的任意值比如用户会话ID来解决。对于preference详细请查看https://www.elastic.co/guide/...偏好这个参数 preference 允许 用来控制由哪些分片或节点来处理搜索请求。 它接受像 _primary, _primary_first, _local, _only_node:xyz, _prefer_node:xyz, 和 _shards:2,3 这样的值, 这些值在 search preference 文档页面被详细解释。但是最有用的值是某些随机字符串它可以避免 bouncing results 问题。例如使用用户的会话ID xyzabc123如下所示GET /test_index/_search?preferencexyzabc123 { query: { match: { test_field: hello } } } { took : 1, timed_out : false, _shards : { total : 1, successful : 1, skipped : 0, failed : 0 }, hits : { total : { value : 2, relation : eq }, max_score : 0.20521778, hits : [ { _index : test_index, _type : _doc, _id : 2, _score : 0.20521778, _source : { test_field : hello, how are you } }, { _index : test_index, _type : _doc, _id : 1, _score : 0.16402164, _source : { test_field : hello you, and world is very good } } ] } }