Skip to content

Commit

Permalink
Fix value for search_after parameter in serach.md (#584)
Browse files Browse the repository at this point in the history
Signed-off-by: pajh0509 <pajh0509@gmail.com>
  • Loading branch information
pajh0509 authored Mar 4, 2024
1 parent bf70d3d commit cd5c6fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Deprecated
### Removed
### Fixed
- Fix wrong documentation for file serach.md regarding `search_after` param ([#584](https://github.com/opensearch-project/opensearch-js/pull/584))
### Security

## [2.3.0]
Expand Down
22 changes: 14 additions & 8 deletions guides/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,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 @@ -162,25 +165,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 cd5c6fd

Please sign in to comment.