Created
August 3, 2017 08:30
-
-
Save larryyangsen/836fc15e3935edfc395a90a0e9a6b7d8 to your computer and use it in GitHub Desktop.
elasticsearch js client scroll await
This file contains hidden or 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
| 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