How to simulate long running Elasticsearch query?

Hi,

We're having issues with our Elasticsearch topology. We're using default topology which behaves not so good when under heavy load, which is happening in the last few weeks.

So we wanted to automatically cancel long running tasks as a safety net to other things we're doing.

To test this cancelation, we need to simulate long running queries. Is there any chance to do this? Of course, this will be done only locally or on dev environment/

I thought there is something like Thread.sleep in script, but I don't see such feature in painless. I found one article that does that in groovy, but no luck in painless.

Thanks in advance

I managed to find a way:

  "query": {
    "function_score": {
      "script_score": {
        "script": {
          "lang": "painless",
          "source": "long total = 0; for (int i = 0; i < 500000; ++i) { total += i; } return total;"
        }
      }
    }
  }
}

Value 500000 needs to be carefully set, it seems what max value is 1 million of statements inside loop.