How to split results on Elasticsearch DSL in Python

I am using Elasticsearch DSL and I would like to view the results. To do this, I need to know the total number of search results. How am I best to do this?

Do I do one search, then do it twice, usually for .hits.total, and the other for elements? Something like that:

response = Link.search().filter("term", run_id=run_id)
total = response.execute().hits.total
links = response[start:end].execute()
+4
source share
1 answer

Try the following:

dsl = Link.search().filter("term", run_id=run_id)
response = dsl[start:end].execute()
links = response.hits.hits
total = response.hits.total

... only hits ElasticSearch once.

+4
source

All Articles