Alw*_*nny 2 multithreading elasticsearch elasticsearch-py
首先,我想让大家知道我知道ElasticSearch Scroll API如何工作的基本工作逻辑。要使用Scroll API,首先,我们需要使用一些滚动值(如1m )调用search方法,然后它将返回一个_scroll_id,该_scroll_id将用于 Scroll 上的下一个连续调用,直到所有文档在循环中返回。但问题是我只想在多线程的基础上使用相同的进程,而不是串行。例如:
如果我有 300000 个文档,那么我想以这种方式处理/获取文档
所以我的问题是,我没有找到任何方法来设置滚动 API 上的from值,如何使用线程使滚动过程更快。不要以序列化的方式处理文档。
我的示例 python 代码
if index_name is not None and doc_type is not None and body is not None:
es = init_es()
page = es.search(index_name,doc_type, scroll = '30s',size = 10, body = body)
sid = page['_scroll_id']
scroll_size = page['hits']['total']
# Start scrolling
while (scroll_size > 0):
print("Scrolling...")
page = es.scroll(scroll_id=sid, scroll='30s')
# Update the scroll ID
sid = page['_scroll_id']
print("scroll id: " + sid)
# Get the number of results that we returned in the last scroll
scroll_size = len(page['hits']['hits'])
print("scroll size: " + str(scroll_size))
print("scrolled data :" )
print(page['aggregations'])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6459 次 |
| 最近记录: |