欢迎投稿

今日深度:

python Elasticsearch 遍历相关数据,

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

www.htsjk.Com true http://www.htsjk.com/Elasticsearch/34955.html NewsArticle 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_...
相关文章
    暂无相关文章
评论暂时关闭