es查询限制10000,使用scroll

报错:

TransportError(500, 'search_phase_execution_exception', 'Result window is too large, from + size must be less than or equal to: 10000 but was 10010. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the index.max_result_window index level setting.')

原因:

这个错误提示意味着你正在尝试从Elasticsearch中检索大量的数据,但是你的请求超过了Elasticsearch的默认结果窗口大小限制。默认情况下,Elasticsearch的结果窗口大小限制为10000,这意味着你一次最多只能检索10000个文档。

为了解决这个问题,你可以使用Elasticsearch的scroll API来检索大量的数据。scroll

API允许你在多个请求之间保持搜索上下文,以便你可以逐步检索大量的数据,而不会超出默认结果窗口大小的限制。

另外,你也可以通过更改Elasticsearch的索引级别设置来增加结果窗口大小限制。你可以通过设置"index.max_result_window"参数来调整结果窗口大小限制。但是,这种方法并不推荐,因为它可能会导致Elasticsearch性能下降,特别是在处理大量数据时。

总之,建议你使用scroll API来检索大量的数据,以避免超出默认结果窗口大小限制。

原代码:

python 复制代码
def main():
for i in range(0, int(allapge(index) / 10) + 2):
	try:
        res = es_yt.search(index=index, body=search_body(i))
        list_es = res['hits']['hits']
        s = helpers.bulk(es_ebscn, list_es)
        print('已完成', i)
        print(s)
    except Exception as e:
        print(e)

使用scroll 新代码:

python 复制代码
def main():
    scroll_time = '2m'  # 滚动查询的保持时间
    page_size = 1000  # 每个滚动请求返回的文档数

    res = es_yt.search(index=index, body=search_body(0), scroll=scroll_time, size=page_size)
    scroll_id = res['_scroll_id']
    scroll_size = res['hits']['total']
    print('scroll_size', scroll_size)

    while (scroll_size > 0):

        list_es = res['hits']['hits']
        print(list_es[0:1])
        if list_es:
            s = helpers.bulk(es_ebscn, list_es)
            print('scroll_size', scroll_size)
            print(s)
            res = es_yt.scroll(scroll_id=scroll_id, scroll=scroll_time)
        else:
            print('结束')
            break

    es_yt.clear_scroll(scroll_id=scroll_id)
相关推荐
BYSJMG31 分钟前
计算机毕业设计选题推荐:基于大数据的心脏病风险数据可视化与分析(Hadoop+Spark+PySpark)
大数据·hadoop·信息可视化·数据分析·spark·课程设计
长谷深风11132 分钟前
好的 Tool Schema,不是字段越全越好
java·大数据·人工智能·ai agent·agent工作流·智能体设计·ai产品设计
TMT星球1 小时前
网易发布2026Q2财报:净收入301亿元,创新驱动长青矩阵稳健增长
大数据
huanqiuworld1 小时前
中策大数据实力如何?从数据、真实性到服务的五维综合评价
大数据
AcaDesign3 小时前
国家/省部市级科技奖答辩PPT_科技进步奖_自然科学奖_技术发明奖|WordinPPT
大数据·人工智能·科技·powerpoint
小淮AI9 小时前
国际教育课程的本土化探索:以枫叶教育三十年为观察样本
大数据·人工智能
龙兵AI增长破局圈.赵老师讲成交10 小时前
只有把过程管好,结果才会出来。
大数据·人工智能·ai·创业创新
qq4078556011 小时前
面向智能补货需求的进销存系统盘点
大数据·人工智能·低代码·制造
CHENGQUAN_kenan11 小时前
佛山亚马逊卖家出口退税合规指南|9610免税、一般贸易退税、无票采购、申报误区全覆盖
大数据·经验分享·笔记·百度
Web3_Daisy12 小时前
从流动性到执行:如何降低 MEV 对 Web3 市场
大数据·人工智能·web3·区块链