Can't paginate using elasticsearch_dsl
See original GitHub issueWhen 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:
- Created 8 years ago
- Reactions:1
- Comments:26 (16 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@sbnajardhane you can always pass in the
preserve_order
attribute to the underlying helper by callings = s.params(preserve_order=True)
before callings.scan()
- that way the sorting will still be applied even when scanning+1 for a more default ES-DSL implementation for pagination 😃