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)
相关推荐
Blossom.1181 小时前
量子通信技术:原理、应用与未来展望
大数据·人工智能·深度学习·安全·机器学习·计算机视觉·量子计算
跨境卫士情报站2 小时前
亚马逊第四个机器人中心将如何降低30%配送成本?
大数据·人工智能·经验分享·机器人
Robot2514 小时前
「华为」持续加码人形机器人赛道!
大数据·人工智能·科技·华为·机器人·自动驾驶
老猿阿浪5 小时前
Git初始化本地已有项目,并推送到远端Git仓库完整操作指南
大数据·git·elasticsearch
码农爱java5 小时前
Elasticsearch 深入分析三种分页查询【Elasticsearch 深度分页】
java·大数据·spring boot·后端·elasticsearch·全文检索
java之迷7 小时前
jenkins使用Send build artifacts over SSH发布jar包目录配置
ssh·jenkins·jar
jdyzzy7 小时前
什么是 ERP、MES、PLM,生产制造中如何应用
大数据·人工智能·制造
gaosushexiangji8 小时前
实验分享|基于千眼狼sCMOS科学相机的流式细胞仪细胞核成像实验
大数据·人工智能·科技·数码相机·计算机视觉
鲁尼的小宝贝9 小时前
基于Flink的数据中台管理平台
java·大数据·clickhouse·flink·yarn
TDengine (老段)9 小时前
TDengine 运维—容量规划
大数据·运维·数据库·时序数据库·tdengine·涛思数据·iotdb