'Is there a way to run sleep command with painless in Elasticsearch 7?

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?

  1. Index a document and then update it (update1).
  2. Update1 starts in background and includes a waiting time (sleep).
  3. 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.
  4. 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.)


Solution 1:[1]

It was possible to do it with Groovy in ES 5 but as of ES 6 onwards, it is not possible to do it with Painless. Also I'm not sure why this would be needed.

Since you're calling via curl, you can simply do it in your shell

% sleep 10s
% curl -XPOST 'localhost:9200/online-shop/shirts/1/_update' -d '{
 "script": "ctx._source.price = 2" 
}' 

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 Val