Skip to content

Instantly share code, notes, and snippets.

@bibhuticoder
Created January 31, 2021 15:57
Show Gist options
  • Save bibhuticoder/62c26b3829e7c6490047674f65415a51 to your computer and use it in GitHub Desktop.
Save bibhuticoder/62c26b3829e7c6490047674f65415a51 to your computer and use it in GitHub Desktop.
let data = [];
try {
let query = {
index: 'index-name',
body: {
query: {
bool: {
// ...
}
},
sort: [{ "unique-property-on-index": "asc" }], // can be both asc & desc
size: 100 // data to retrieve at a time
}
};
var lastHits;
do {
lastHits = (await es.client.search(query)).body.hits.hits;
if (lastHits.length > 0) {
data = data.concat(lastHits);
query.body["search_after"] = [lastHits.pop()._source["unique-property-on-index"]];
}
} while (lastHits.length > 0);
// you get your results on "data" array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment