question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't paginate using elasticsearch_dsl

See original GitHub issue

When I want to paginate through the search results, not iterate as the scan does from elasticsearch.helpers.

My current workaround is something like this

search = Search()
...
# construct your search query
...
result = search.params(search_type='scan', scroll='1m').execute()
scroll_id = result.scroll_id
# Now start using scroll_id to do the pagination,
# but I have to use Elasticsearch.scroll which returns dictionaries not a Result object
client = connections.get_connection()
while data_to_paginate:
  result = Response(client.scroll(scroll_id, scroll='1m'))

There probably should be a helper function that should abstract at least the following part

client = connections.get_connection()
result = Response(client.scroll(scroll_id, scroll='1m'))

Maybe even getting the scroll_id from the result. Basically the user probably shouldn’t be getting a client and manually constructing a Response object.

@HonzaKral what do you think? If we agree on the interface I could implement that since I am probably going to do that for my project.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:26 (16 by maintainers)

github_iconTop GitHub Comments

3reactions
honzakralcommented, Oct 18, 2018

@sbnajardhane you can always pass in the preserve_order attribute to the underlying helper by calling s = s.params(preserve_order=True) before calling s.scan() - that way the sorting will still be applied even when scanning

1reaction
saurfanggcommented, Jul 20, 2016

+1 for a more default ES-DSL implementation for pagination 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Paginate search results | Elasticsearch Guide [8.5] | Elastic
When paging search hits, you might occasionally see that documents with the same sort values are not ordered consistently.
Read more >
How to Optimize Your Elasticsearch Queries Using Pagination
The simplest method of pagination uses the from and size parameters available in Elasticsearch's search API. By default, from is 0 and size...
Read more >
Elasticsearch Pagination Techniques: SearchAfter, Scroll ...
The default mechanism to fetch many results in Elasticsearch is pagination. When you send a query to Elasticsearch it will always use the...
Read more >
Python elasticsearch-dsl django pagination - Stack Overflow
A very simple solution is to use MultipleObjectMixin and extract your Elastic results in get_queryset() by overriding it.
Read more >
Pagination of results in Elasticsearch | from & size ... - YouTube
In this elastic search tutorial, we discuss about Paginating the search results or search result Pagination. This is part of Query DSL ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found