Elasticsearch 7.11 Python 扫描是无限的

问题描述

page = helpers.scan(
        c,query=q,index=idx,scroll='5m',size=1000,)

    i = 0
    for hit in page:
        i = i + 1
        if i % 1000 == 0 and i > 0:
            print("dump finished %i items" % i)
        yield {"_source": hit['_source'],"_id": hit['_id']}

问题是这个循环扫描永远不会结束,最后一批结果可能会被无限循环。
我将数据转储到一个文件中,第一个条目出现了 1 次。最后一个条目被重复写入,循环继续。

不确定是我的代码还是库中的错误

更新 1:

    slices = [
        delayed(iterate_slice)(1,es_host,idx,slices,q,size,logger_name)
    ]

    return db.from_delayed(slices)

那么 iterate_slice 的代码如下:

    page = helpers.scan(
        c,size=10000,)

    i = 0
    for hit in page:
        i++
        if i % 1000 == 0 and i > 0:
            print("dump finished %i items" % i)
        yield {"_source": hit['_source'],"_id": hit['_id']}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)