Elasticsearch returning inconsistent data

I have an index which stores user information. On one side I am updating the index with changes. The other side I am search user with display name. I have a problem now.
Say { "name": "gOz7nH2Sk3242342"}. Then i change it to { "name": "gOz7nH2Sk8ethXV4"}. I started a client which in a loop searches for the prefix "gOz7nH".
My response goes.
{ "name": "gOz7nH2Sk3242342"}
{ "name": "gOz7nH2Sk8ethXV4"}
{ "name": "gOz7nH2Sk3242342"}
{ "name": "gOz7nH2Sk8ethXV4"}
{ "name": "gOz7nH2Sk8ethXV4"}

I don't understand. For a moment I get the old data and then it returns the new data. Where is this inconsistency coming from?

By default Elasticsearch takes up to one second to make indexed data available for search. However this is a setting applied to each shard. So if you are hitting shard0 first,. which had already done that refresh, but the second search hits a copy of that shard which has not, you may encounter this situation. You could try to alleviate this with the refresh=wait_for setting when indexing data.

--Alex

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.