python Elasticsearch 遍历相关数据

来源:互联网 发布:@徐老师淘宝店号是多少 编辑:程序博客网 时间:2024/06/16 21:44

一开始用的是这个

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的关键词,不然会报错

原创粉丝点击