0

Updating or removing a record in Elastic Search sometimes takes a second or so to fully make its way through the system such that a new search will show the change you made.

Is there some way to block the thread until elastic "verifies" that the requested operation has completed?

Specific example:

  1. User goes to detail page for an object
  2. User deletes that object, we delete from database and make request to elastic to delete it
  3. elastic returns 200 OK that the request was ok
  4. User is redirected back to a list page where we show elastic results, but the record is still showing

Usually after a second if you refresh it will be gone from elastic results as expected, but that amount of time is not deterministic. Is there some way to call an elastic operation such that it doesn't return a 200 OK until the operation has fully completed processing?

Only other way I can think to do this is to query elastic every Xms for the deleted object until elastic returns no result. This feels very hacky, anyone found a better solution to this use case?

DLeh
  • 23,806
  • 16
  • 84
  • 128
  • I think i may have found a solution in the "Refresh" option on the bulk update (which we use for almost all our operations), but I'm not sure if that will cause performance issues. – DLeh Aug 03 '18 at 13:02
  • this might also be worth reading: https://stackoverflow.com/questions/31499575/how-to-deal-with-elasticsearch-index-delay/34391272#34391272 – Val Aug 03 '18 at 13:03
  • Thanks @val. We do indeed do that in cases where it applies, like deleting from a list for instance. But in this case since we're directing to a new page it's hard to preserve this type of thing. I think using the `refresh=true` option should work in my case. Since it is just a single use case and i won't apply it to all operations, I hope that it won't be a performance hit – DLeh Aug 03 '18 at 13:13
  • 1
    I would use `refresh=wait_for` instead – Val Aug 03 '18 at 13:22
  • @Val problem with `wait_for` is that sometimes that one second is too long because the app immediately goes back to elastic to get data and the deleted record still returns. thanks for the advice though! – DLeh Aug 08 '18 at 16:02
  • Well, pay attention then to not call refresh too often or you might risk some performance issues – Val Aug 08 '18 at 16:12

0 Answers0