Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong documentation for file serach.md regarding search_after param #584

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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 @@ -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
Loading