Skip to content

Commit

Permalink
Fix value for search_after parameter in serach.md
Browse files Browse the repository at this point in the history
Signed-off-by: pajh0509 <pajh0509@gmail.com>
  • Loading branch information
pajh0509 committed Aug 11, 2023
1 parent dbf4d1c commit cfd1988
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions guides/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,27 @@ const page_1 = await client.search({
size: 2,
body: search_body
});
const documents_1 = page_1.body.hits.hits;

const page_2 = await client.search({
index: 'movies',
size: 2,
body: {
...search_body,
search_after: page_1[page_1.length - 1].sort
search_after: documents_1[documents_1.length - 1].sort
}
});
const documents_2 = page_2.body.hits.hits;

const page_3 = await client.search({
index: 'movies',
size: 2,
body: {
...search_body,
search_after: page_2[page_2.length - 1].sort
search_after: documents_2[documents_2.length - 1].sort
}
})
});
const documents_3 = page_3.body.hits.hits;
```
### Pagination with scroll
When retrieving large amounts of non-real-time data, you can use the `scroll` parameter to paginate through the search results.
Expand Down Expand Up @@ -182,25 +185,28 @@ const page_1 = await client.search({
size: 2,
body: pit_search_body
});
console.log(page_1.body.hits.hits);
const documents_1 = page_1.body.hits.hits;
console.log(documents_1);

const page_2 = await client.search({
size: 2,
body: {
...pit_search_body,
search_after: page_1[page_1.length - 1].sort
search_after: documents_1[documents_1.length - 1].sort
}
});
console.log(page_2.body.hits.hits);
const documents_2 = page_2.body.hits.hits;
console.log(documents_2);

const page_3 = await client.search({
size: 2,
body: {
...pit_search_body,
search_after: page2[page_2.length-1].sort
search_after: documents_2[documents_2.length-1].sort
}
});
console.log(page_3.body.hits.hits);
const documents_3 = page_3.body.hits.hits;
console.log(documents_3);

/** Print out the titles of the first 3 pages of results */
console.log(page_1.map(hit => hit._source.title));
Expand Down

0 comments on commit cfd1988

Please sign in to comment.