Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

How to add parameters on '/_search' method like this '/_search?preference=zxcvzxd123' #699

Open
dap3ng opened this issue Mar 22, 2021 · 0 comments

Comments

@dap3ng
Copy link

dap3ng commented Mar 22, 2021

Say the same user runs the same request twice in a row and documents do not come back in the same order both times, this is a pretty bad experience isn’t it? Unfortunately this is something that can happen if you have replicas (index.number_of_replicas is greater than 0). The reason is that Elasticsearch selects the shards that the query should go to in a round-robin fashion, so it is quite likely if you run the same query twice in a row that it will go to different 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 in (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.

How to add parameters on '/_search' method like this '/_search?preference=zxcvzxd123'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant