In the old version of Elasticsearch, we can do:
% curl -XPOST 'localhost:9200/online-shop/shirts/1/_update' -d '{
"script": "Thread.sleep(10000); ctx._source.price = 2"
}'
How to do the sleep with painless in Elasticsearch 7?
- Index a document and then update it (update1).
- Update1 starts in background and includes a waiting time (sleep).
- During that sleep, issue another update command (update2) that modifies the document. This change occurs between update1’s fetch of the original document and its re-indexing operation.
- Instead of canceling the changes of update2, update1 fails because the document is already at version 2. At this point you have the chance to retry update1 and apply the changes in version 3. (See listing 3.6.)