# JS client for elasticsearch times out on scroll or takes a long time

**URL:** <https://discuss.elastic.co/t/js-client-for-elasticsearch-times-out-on-scroll-or-takes-a-long-time/358495>\
**Category:** Elasticsearch\
**Created:** [April 30, 2024, 12:58pm UTC](https://discuss.elastic.co/t/js-client-for-elasticsearch-times-out-on-scroll-or-takes-a-long-time/358495 "2024-04-30T12:58:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BOYO](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/boyo/32/124388_2.png) [@BOYO](https://discuss.elastic.co/u/BOYO)\
**Post date:** [April 30, 2024, 12:58pm UTC](https://discuss.elastic.co/t/js-client-for-elasticsearch-times-out-on-scroll-or-takes-a-long-time/358495/1 "2024-04-30T12:58:35Z")

</div>

For a particular usecase I'm trying to benchmark how long it would take to fetch all the entries for a particular search. I used the official client helper for scrolling all the entries like below, but it times out in some cases if the number of entries are very large and I can also see more delay for queries with \<10K

> **[Scroll | Elasticsearch JavaScript Client \[8.13\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/scroll_examples.html)**

```auto
const client = new Client({
    node: process.env.ELASTIC_NODE,
    auth: {
        username: process.env.ELASTIC_U,
        password: process.env.ELASTIC_P
    },
    tls: {
        rejectUnauthorized: false
    }
 })

 async function * scrollSearch (params) {
    let response = await client.search(params);

    while (true) {
      const sourceHits = response.hits.hits
  
      if (sourceHits.length === 0) {
        break
      }
      
      yield sourceHits.length

  
      if (!response._scroll_id) {
        break
      }
  
      response = await client.scroll({
        scroll_id: response._scroll_id,
        scroll: params.scroll
      })
    }
  }
  
  async function run (query) {
    let hits = 0;

    const params = {
        index: process.env.INDEX,
        scroll: '1m',
        size: 10000,
        query : {
            bool : {
                must : query
            }
        }
      }
    
    for await (const noOfHits of scrollSearch(params)) {
      hits += noOfHits;
    }

    return hits;
  }

```

Is there any particular reason for it ?
