我正在使用Elasticsearch DSL,我想对结果进行分页。为此,我需要知道搜索结果的总数。我该如何做到最好?
我是否进行一次搜索,然后执行两次,一次针对.hits.total
,另一次针对项目进行切片?像这样:
response = Link.search().filter("term", run_id=run_id)
total = response.execute().hits.total
links = response[start:end].execute()
答案 0 :(得分:5)
试试这个:
dsl = Link.search().filter("term", run_id=run_id)
response = dsl[start:end].execute()
links = response.hits.hits
total = response.hits.total
...只能击中ElasticSearch一次。