Skip to content

Implement efficient pagination helpers using search_after #802

Open
@honzakral

Description

@honzakral

Currently any of the pagination needs to be done manually either via slicing (which can be inefficient for deep pagination) or using search_after (0), which can be complex. What I propose is to introduce several new methods on Search objects:

def get_page(self, page_no):
    """
    use slicing to get the `page_no` page and return a response (it will execute your search)
    """

def get_next_page(self, last_hit, step=1):
    """
    use `search_after` and return a response representing page of the response + step
    """

def get_previous_page(self, first_hit, step=1):
    """
    similar to get_next_page but will have to reverse the order first to be able to use search_after
    """

and helper methods on Response to retrieve last_hit and first_hit (self.hits[0/-1].meta.sort) and also to directly use those to call get_next/previous_page.

0 - https://www.elastic.co/guide/en/elasticsearch/reference/6.1/search-request-search-after.html

Or do people think this should be a separate object/module altogether? is there anything I am missing? (number of pages? Direct jump to last/first page?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions