您的位置:首页 > 编程语言 > Python开发

python Elasticsearch 遍历相关数据

2017-11-28 23:12 78 查看
一开始用的是这个

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的关键词,不然会报错
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  elasticsearch