add a 5.0+ exapmle for the scroll api
This commit is contained in:
@ -1,6 +0,0 @@
|
||||
module.exports = [
|
||||
{
|
||||
version: '*',
|
||||
examples: {}
|
||||
}
|
||||
]
|
||||
28
docs/_examples/scroll_5.0+.asciidoc
Normal file
28
docs/_examples/scroll_5.0+.asciidoc
Normal file
@ -0,0 +1,28 @@
|
||||
.Collect every title in the index that contains the word "test"
|
||||
[source,js]
|
||||
---------
|
||||
var allTitles = [];
|
||||
|
||||
// first we do a search, and specify a scroll timeout
|
||||
client.search({
|
||||
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'
|
||||
}, function getMoreUntilDone(error, response) {
|
||||
// collect the title from each response
|
||||
response.hits.hits.forEach(function (hit) {
|
||||
allTitles.push(hit._source.title);
|
||||
});
|
||||
|
||||
if (response.hits.total > allTitles.length) {
|
||||
// ask elasticsearch for the next set of hits from this search
|
||||
client.scroll({
|
||||
scrollId: response.scroll_id,
|
||||
scroll: '30s'
|
||||
}, getMoreUntilDone);
|
||||
} else {
|
||||
console.log('every "test" title', allTitles);
|
||||
}
|
||||
});
|
||||
---------
|
||||
Reference in New Issue
Block a user