Getting task status in painless script

Hi Team,

I am using ES 6.8.7.

I am trying to avoid parallel execution of long running _update_by_query requests in Elasticsearch as they are CPU and Memory intensive. I want to make sure that the next task is kept in sleep state until previous is done so that a queue of such tasks is built within ES itself.

For this my plan is to,

  • Send one task and get the task id
  • In next task, I will check using painless script if task against the above task id is still running. If so, keep the current task sleeping for the completion of previous
  • As soon as, the script knows that the task is completed, it will start its work.

Please help me if there is a possible solution to the second step in above.

Thanks in Advance!!!