Created
January 31, 2021 15:57
-
-
Save bibhuticoder/62c26b3829e7c6490047674f65415a51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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