Skip to content

Instantly share code, notes, and snippets.

@larryyangsen
Created August 3, 2017 08:30
Show Gist options
  • Select an option

  • Save larryyangsen/836fc15e3935edfc395a90a0e9a6b7d8 to your computer and use it in GitHub Desktop.

Select an option

Save larryyangsen/836fc15e3935edfc395a90a0e9a6b7d8 to your computer and use it in GitHub Desktop.
elasticsearch js client scroll await
const options= {
index:'index1',
scroll: '2m',
type:'test',
allowNoIndices: true,
ignoreUnavailable: true,
body: {
size: 100,
from: 0
}
};
let totalResults = 0,
scrollId = '',
searchResults = await esClient.search(options);
while (searchResults.hits.total > totalResults) {
scrollId = searchResults._scroll_id;
searchResults.hits.hits.map(hit => {
// do something
totalResults++;
});
searchResults = await esClient.scroll({
scrollId: scrollId,
scroll: '2m'
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment