想象一下有两个文档有一样值的时间戳字段,搜索结果用 timestamp 字段来排序。 因为搜索请求是在全部有效的分片副本间轮询的,那就有可能发生主分片处理请求时,这两个文档是一种顺序, 而副本分片处理请求时又是另外一种顺序。html
详细请查看
https://www.elastic.co/guide/...node
偏好这个参数 preference 容许 用来控制由哪些分片或节点来处理搜索请求。 它接受像 _primary, _primary_first, _local, _only_node:xyz, _prefer_node:xyz, 和 _shards:2,3 这样的值, 这些值在 search preference 文档页面被详细解释。
可是最有用的值是某些随机字符串,它能够避免 bouncing results 问题。
例如,使用用户的会话ID xyzabc123,以下所示:elasticsearch
GET /test_index/_search?preference=xyzabc123 { "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" } } ] } }