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] add support for search(search_after) #337

Open
r-mendes opened this issue Mar 21, 2023 · 10 comments
Open

[FEATURE] add support for search(search_after) #337

r-mendes opened this issue Mar 21, 2023 · 10 comments
Labels
CCI enhancement New feature or request good first issue Good for newcomers

Comments

@r-mendes
Copy link

What is the bug?

The search method doesn't support search_after parameter.

How can one reproduce the bug?

  1. Instantiate a OpenSearch object;
  2. Run a search using the sort parameter;
  3. Get the result and then look for the last hit entry;
  4. From the last hit entry, fetch the sort field value;
  5. Run a search passing the value fetched in step 4 in the searh_after parameter;
  6. It will be shown a messaging informing that this parameter is not supported;

What is the expected behavior?

The search_after parameter supposed to be supported in the most recent version of the library.

What is your host/environment?

Linux, Ubuntu 22.04

Do you have any screenshots?

Do you have any additional context?

The lack of this parameter block the usage of queries' pagination using the search_after and Point-in-time approach.

@r-mendes r-mendes added bug Something isn't working untriaged Need triage labels Mar 21, 2023
@margulanz
Copy link

I will try to work on this issue

@harshavamsi harshavamsi added CCI and removed untriaged Need triage labels Mar 28, 2023
@ReinGrad
Copy link

ReinGrad commented Apr 4, 2023

The OpenSearch library currently does not support the search_after parameter, which is used for pagination in search queries. This means that users cannot easily paginate large result sets using the search_after parameter in OpenSearch.

It would be possible that the OpenSearch library should support the search_after parameter, since this is a common feature in other search libraries such as ElasticSearch. It is possible that this feature may be added in a future version of the library.

One of the options may be switching to another search library that supports the search_after parameter, or implementing a different pagination strategy using the from and size parameters. It may also be possible to contribute to the OpenSearch library to add support for the search_after parameter.

@margulanz
Copy link

As I understand, this issue may be considered as closed? @ReinGrad?

@margulanz margulanz removed their assignment Apr 15, 2023
@morrissimo
Copy link

FYI I've been able to use the .extra() capability as a good-enough workaround to use search_after - eg

# initial query
>>> query.to_dict()
{
  "query": {
    "match_all": {}   # or whatever
  },
  "from": 0,
  "size": 1,
  "sort": [
    "field1.keyword",
    "field2.keyword"
  ]
}
# define search_after spec
>>> search_after_spec = [
    "some_field1_value",
    "some_field2_value"
]
# apply search_after spec to existing query
>>> query = query.extra(search_after=search_after_spec)
# query with search_after added
>>> query.to_dict()
{
  "query": {
    "match_all": {}   # or whatever
  },
  "from": 0,
  "size": 1,
  "sort": [
    "field1.keyword",
    "field2.keyword"
  ],
  "search_after": [
    "some_field1_value",
    "some_field2_value"
  ]
}

FWIW, I've also been using this same .extra() approach to use point-in-time with search_after

@wbeckler
Copy link
Contributor

If anyone wants to add this as a feature, I think it still makes sense. Or if anyone wants to update the user guide examples for now.

@saimedhi saimedhi added the good first issue Good for newcomers label Sep 7, 2023
@dblock
Copy link
Member

dblock commented Nov 10, 2023

@r-mendes or @morrissimo Any interest in picking this up?

@dblock dblock added enhancement New feature or request and removed bug Something isn't working labels Nov 10, 2023
@dblock dblock changed the title [BUG] search method doesn't support search_after parameter [FEATURE] add support for search(search_after) Nov 10, 2023
@dblock
Copy link
Member

dblock commented Nov 10, 2023

Also, is https://github.com/opensearch-project/opensearch-py/blob/d8dc5474b7e7e2b443d9858c21d8f7be93306704/guides/search.md?plain=1#L140C37-L140C49 not the way to do this, meaning we still need different support for it?

@dblock
Copy link
Member

dblock commented Nov 27, 2024

@nathaliellenaa

@nathaliellenaa
Copy link
Contributor

I will look into this issue

@nathaliellenaa
Copy link
Contributor

nathaliellenaa commented Nov 29, 2024

It seems that there is already a support for search_after via API spec. I added a sync and an async sample that uses the search_after parameter #859. Is this what you are looking for? If so, I propose we can close this issue @r-mendes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CCI enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

9 participants