Home > Software engineering >  Clear scroll request using JavaScript client (Not use client helpers )
Clear scroll request using JavaScript client (Not use client helpers )

Time:10-08

I could not get an API to clear scroll request in JavaScript client. I am fetching data recursively using scroll API and I want clear scroll request if user switches to another tab.

I am using doc here => https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/master/scroll_examples.html

To fetch at start

await client.search({
    index: 'my index',
    scroll: '300s',
    size: 500,
    query: {
      match_all: {}
    }
  })

To fetch using scroll it next time

await client.scroll({
        scrollId: body._scroll_id,
        scroll: '30s'
      })

At the end, I want clear scroll request and I haven't found that in docs.

CodePudding user response:

You can use clearScroll for clearning scroll using specific id.

await client.clearScroll({
        scrollId: body._scroll_id
      })

You can check this documentation.

  • Related