# How to simulate long running Elasticsearch query?

**URL:** <https://discuss.elastic.co/t/how-to-simulate-long-running-elasticsearch-query/264288>\
**Category:** Elasticsearch\
**Created:** [February 15, 2021, 9:09am UTC](https://discuss.elastic.co/t/how-to-simulate-long-running-elasticsearch-query/264288 "2021-02-15T09:09:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aldm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aldm/32/45644_2.png) [@aldm](https://discuss.elastic.co/u/aldm)\
**Post date:** [February 15, 2021, 9:09am UTC](https://discuss.elastic.co/t/how-to-simulate-long-running-elasticsearch-query/264288/1 "2021-02-15T09:09:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aldm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aldm/32/45644_2.png) [@aldm](https://discuss.elastic.co/u/aldm)\
**Post date:** [February 15, 2021, 9:48am UTC](https://discuss.elastic.co/t/how-to-simulate-long-running-elasticsearch-query/264288/2 "2021-02-15T09:48:36Z")

</div>

I managed to find a way:

```auto
  "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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 15, 2021, 9:48am UTC](https://discuss.elastic.co/t/how-to-simulate-long-running-elasticsearch-query/264288/3 "2021-03-15T09:48:59Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
