Search code examples
asynchronouselasticsearchbulk

Elasticsearch bulk update followed by search


In my server I update some documents using bulk API:

{"update":{"_type":"post","_retry_on_conflict":"3","_index":"xxxx","_id":"yyyy"}}
{"doc":{"sentiment":"positive","mood":1,"upgrade":true}}

After I get the response I make a new request for the same document using search:

{"query":{"filtered":{"filter":{"ids":{"values":["yyyy"]}}}}}

But the returned document has no updated value( Still has the old value ). If I wait for some time the updated value appears. I Think that occurs because bulk is async? Is there any way to fix this?


Solution

  • you can use refresh api to force index update, or even add ?refresh=true at the end of bulk command. But normally not recommended. Also, If there are more than one Node, you may need to use synced flush.