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

[FEATURE] searchApi should support search_after #476

Closed
mstykow opened this issue Apr 4, 2023 · 4 comments
Closed

[FEATURE] searchApi should support search_after #476

mstykow opened this issue Apr 4, 2023 · 4 comments

Comments

@mstykow
Copy link

mstykow commented Apr 4, 2023

Is your feature request related to a problem?

The OpenSearch API supports pagination using the search_after parameter: https://opensearch.org/docs/2.4/opensearch/search/paginate/#the-search_after-parameter

However, it seems that opensearch-js's searchApi does not support this parameter: https://opensearch-project.github.io/opensearch-js/2.1/API-Search.html

What solution would you like?

searchApi allows pagination using search_after.

What alternatives have you considered?

Using pagination with size and from, but this has serious limitations.

@mstykow
Copy link
Author

mstykow commented Apr 4, 2023

I found this Stackoverflow answer for elasticsearch-js saying that search_after should be part of the body. If that's true, perhaps some documentation would be helpful.

https://stackoverflow.com/questions/62716360/elasticsearch-search-after-with-nodejs

@nhtruong nhtruong removed the untriaged label Apr 5, 2023
@nhtruong
Copy link
Collaborator

nhtruong commented Apr 5, 2023

search_after is not a URL parameter of the search endpoint. It's actually a body parameter:

# GET shakespeare/_search
{
  "size": 10,
  "query": {
    "match": {
      "play_name": "Hamlet"
    }
  },
  "search_after": [ 1, "32635"],
  "sort": [
    { "speech_number": "asc" },
    { "_id": "asc" } 
  ]
}

I see that you mean though. It would be a lot more convenient if you can just pass search_after as a param of the client.search method instead of wedging it into the body. Unfortunately, we have a pattern where our API methods are consistent with the API endpoints they represent. Breaking away from that pattern is a change that will introduce edge cases, though it might be worth it? That's up for debate.

Anyhow, we're actually have a series of Guides in the work that includes sample code for search, that will hopeful help you avoid this pitfall in the future :)

@mstykow
Copy link
Author

mstykow commented Apr 5, 2023

Gotcha. Looking at your example, it looks like search_after and sort should behave the same way which is adding to the confusion of why search_after cannot be passed as a param.

@nhtruong
Copy link
Collaborator

I think this request is more appropriate for the OS cluster repo. The client is just following the API defined by the cluster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants