'Elastic search update & refresh API
I am integrating elastic search with my Nest application. positing my workflow and question below.
flow:
- front-end updating one entity, so in back-end updates the primary storage MYSQL and cache storage elastic search.
- Immediately front-end hit the get request to get the updated entity, so the back-end fetches the entity from elastic-search and sends a response to the front-end.
- Now the issue is sometimes elastic search giving not updated data due to index not refreshed.
Solutions:
- We can use the
refresh:'wait-for'config in the update API. - We can trigger the refresh API to refresh the indices
- The question is, after the update API, if we trigger the refresh API without waiting for the result. in meantime, if the front-end requested the data what will happen, the elastic search will wait for the refresh indices operation completion or will it serve old data?
Solution 1:[1]
As you already know Elasticsearch provides near real time searches, and if you are making a search call, as soon as document is indexed to Elasticsearch, it will not be available unless refresh happened on the index.
Now, As you mentioned, you can solve the issue by using the wait_for with your index/update operation, only downside is that its resource intensive and if you do it frequently on a large index, it can cause severe performance issues in your cluster.
Your second option will not work, as you can still query the Elasticsearch from FE before refresh finishes and you will get obsolete data.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
