client.scroll([params, [callback]])

Scroll a search request (retrieve the next set of results) after specifying the scroll parameter in a search() call.

Check the API Conventions and the elasticsearch docs for more information pertaining to this method.

Collect every title in the index that contains the word "test".

const allTitles = [];
const responseQueue = [];

// start things off by searching, setting a scroll timeout, and pushing
// our first response into the queue to be processed
  index: 'myindex',
  scroll: '30s', // keep the search results "scrollable" for 30 seconds
  source: ['title'], // filter the source to only include the title field
  q: 'title:test'

while (responseQueue.length) {
  const response = responseQueue.shift();

  // collect the titles from this response
  response.hits.hits.forEach(function (hit) {

  // check to see if we have collected all of the titles
  if ( === allTitles.length) {
    console.log('every "test" title', allTitles);

  // get the next response if there are more titles to fetch
    await client.scroll({
      scrollId: response._scroll_id,
      scroll: '30s'



DurationString — Specify how long a consistent view of the index should be maintained for scrolled search


String — The scroll ID


Boolean — Indicates whether should be rendered as an integer or an object in the rest search response


Object, JSON — An optional request body, as either JSON or a JSON serializable object. See the elasticsearch docs for details about what can be specified here.

back to top