python Elasticsearch 遍历相关数据,
一开始用的是这个
res = es.search(
index='xxxxx*/',
#_source=['localtime', 'request'],
body=actor_count_json,
search_type="query_then_fetch",
scroll="1m"
)
scrollId = res["_scroll_id"]
page_size = res['hits']['total']
for item in xrange(10):
response = es.scroll(scroll_id=scrollId, scroll="1s", )
scrollId = response["_scroll_id"]
print scrollId
for doc in res["hits"]["hits"]:
pass#print doc["_source"]["online_time"]
但是拉取的总是同一个分片的数据,尝试用response来替换scrollid,但是没效果,最终弃用,如果有熟悉的好人,希望可以指点一下。
最终用的是
ret = helpers.scan(es, query=query, index=index,preserve_order=True)
需要增加后面的perserver的关键词,不然会报错
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。