tra*_*nes 5 python pagination iterator elasticsearch
我正在使用elasticsearch滚动API。在某些情况下,我想返回第n页的匹配,而不返回前几页的匹配。我相信这应该像一个迭代器。因此,我只想将迭代器传递到前几页,但实际上要返回第n页的匹配。
我当前的代码是
initial_request = client.search(index = index, doc_type = doc_type, body = q, scroll = str(wait_time) + 'm', search_type = 'scan', size = size)
sid = initial_request['_scroll_id'] ## scroll id
total_hits = initial_request['hits']['total'] ## how many results there are.
scroll_size = total_hits ## set this to a positive value initially
while scroll_size > 0:
p += 1
print "\t\t Scrolling to page %s ..." %p
page = client.scroll(scroll_id = sid, scroll = str(wait_time) + 'm')
sid = page['_scroll_id'] # Update the scroll ID
scroll_size = len(page["hits"]["hits"]) ## no. of hits returned on this page
## then code to do stuff w/ that page's hits.
Run Code Online (Sandbox Code Playgroud)
但page = client.scroll(...)实际上会将该网页的匹配发送回我的本地计算机。我只想pass在前n个页面上,然后在此之后开始发送页面的匹配。
有任何想法吗?
| 归档时间: |
|
| 查看次数: |
669 次 |
| 最近记录: |