ES查询报错:entity content is too long [142501157] for the configured buffer limit [104857600]

这篇具有很好参考价值的文章主要介绍了ES查询报错:entity content is too long [142501157] for the configured buffer limit [104857600]。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

java - org.apache.http.ContentTooLongException: entity content is too long [105539255] for the configured buffer limit [104857600] - Stack Overflow

在生产环境批量同步数据的时候,我写了一个查询请求,然后直接报错:entity content is too long [142501157] for the configured buffer limit [104857600]

具体内容如下:

Caused by: org.apache.http.ContentTooLongException: entity content is too long [142501157] for the configured buffer limit [104857600]
        at org.elasticsearch.client.HeapBufferedAsyncResponseConsumer.onEntityEnclosed(HeapBufferedAsyncResponseConsumer.java:76)
        at org.apache.http.nio.protocol.AbstractAsyncResponseConsumer.responseReceived(AbstractAsyncResponseConsumer.java:137)
        at org.apache.http.impl.nio.client.MainClientExec.responseReceived(MainClientExec.java:315)
        at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseReceived(DefaultClientExchangeHandlerImpl.java:151)
        at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.responseReceived(HttpAsyncRequestExecutor.java:315)
        at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:255)
        at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)
        at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)
        at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114)
        at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)
        at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)
        at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
        at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)
        at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
        at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591)
        at java.lang.Thread.run(Thread.java:748)
        Suppressed: org.apache.http.ContentTooLongException: entity content is too long [142501157] for the configured buffer limit [104857600]
                ... 16 more
                Suppressed: org.apache.http.ContentTooLongException: entity content is too long [142501157] for the configured buffer limit [104857600]
                        ... 16 more

HttpAsyncResponseConsumerFactory类中:

ES查询报错:entity content is too long [142501157] for the configured buffer limit [104857600]

HeapBufferedAsyncResponseConsumer类中有一个判断:返回的内容长度大于限定的100MB就会抛出ContentTooLongException异常。

ES查询报错:entity content is too long [142501157] for the configured buffer limit [104857600]

我这里用的依赖是:

            <dependency>
                <groupId>org.elasticsearch.client</groupId>
                <artifactId>elasticsearch-rest-client</artifactId>
                <version>6.6.2</version>
            </dependency>

            <dependency>
                <groupId>org.elasticsearch.client</groupId>
                <artifactId>transport</artifactId>
                <version>6.6.2</version>
            </dependency>

            <dependency>
                <groupId>org.elasticsearch.client</groupId>
                <artifactId>elasticsearch-rest-high-level-client</artifactId>
                <version>6.6.2</version>
            </dependency>

            <dependency>
                <groupId>org.elasticsearch</groupId>
                <artifactId>elasticsearch</artifactId>
                <version>6.6.2</version>
            </dependency>

而我们对es进行查询操作,或者其他增删改操作是,都会默认使用如下的RequestOptions.DEFAULT

ES查询报错:entity content is too long [142501157] for the configured buffer limit [104857600]

进入RequestOptions.DEFAULT看它的代码:这里用了HeapBufferedResponseConsumerFactory.DEFAULT

ES查询报错:entity content is too long [142501157] for the configured buffer limit [104857600]

而这个HeapBufferedResponseConsumerFactory.DEFAULT,就是我们之前看到的,已经被限制了100MB返回值的HeapBufferedResponseConsumerFactory。

ES查询报错:entity content is too long [142501157] for the configured buffer limit [104857600]

所以有两种方式可以解决这个bug。

方式一:

不使用默认的RequestOptions.DEFAULT,而通过使用自定义RequestOptions的方式(ES官方api已经给我们开放出来了):

RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
builder.setHttpAsyncResponseConsumerFactory(
    new HttpAsyncResponseConsumerFactory
    //修改为500MB
    .HeapBufferedResponseConsumerFactory(500 * 1024 * 1024));

RequestOptions requestOptions=builder.build();

方式二:

如果不方便修改怎么办,例如我们使用的是Spring Data ElasticSearch或者是其他的一些框架,而它默认使用的也是RequestOptions.DEFAULT

ES查询报错:entity content is too long [142501157] for the configured buffer limit [104857600]

这时候我们可以通过java反射进行修改:

        //设置es查询buffer大小
        RequestOptions requestOptions = RequestOptions.DEFAULT;
        Class<? extends RequestOptions> reqClass = requestOptions.getClass();
        Field reqField = reqClass.getDeclaredField("httpAsyncResponseConsumerFactory");
        reqField.setAccessible(true);
        //去除final
        Field modifiersField = Field.class.getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
        modifiersField.setInt(reqField, reqField.getModifiers() & ~Modifier.FINAL);

        //设置默认的工厂
        reqField.set(requestOptions, new HttpAsyncResponseConsumerFactory() {
            @Override
            public HttpAsyncResponseConsumer<HttpResponse> createHttpAsyncResponseConsumer() {
                //500MB
                return new HeapBufferedAsyncResponseConsumer(5 * 100 * 1024 * 1024);
            }
        });

如果你使用的是springmvc,那么可以把这段代码加入到拦截器中,这样可以拦截需要自定义返回值大小的es请求文章来源地址https://www.toymoban.com/news/detail-445900.html

到了这里,关于ES查询报错:entity content is too long [142501157] for the configured buffer limit [104857600]的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 报错Command line is too long. Shorten the command line xxx【解决办法】

    运行springboot项目的时候,出现报错,报错信息如下: Error running OrderServiceBoot. Command line is too long. Shorten the command line via JAR manifest or via a classpath file and rerun. 报错原因: springboot项目启动命令过长 解决办法 解决方法有两种,正如报错信息截图所示,缩短命令行或者改为应用程

    2024年02月11日
    浏览(38)
  • 查询ES报错429 circuit_breaking_exception,“reason“:“[parent] Data too large, data for \[<http_request\>\]

    查询ES报错:429 Too Many Requests;circuit_breaking_exception,”reason”:”[parent] Data too large, data for [http_request]“ 问题 :ES查询报错:429 Too Many Requests;circuit_breaking_exception,“reason”:“[parent] Data too large, data for [http_request]” 原因 :ES查询缓存占用内存过大,超过阈值(默认70%),查

    2024年02月12日
    浏览(31)
  • Command line is too long

    目录 一、遇到的问题 二、使用环境 三、问题分析 四、解决方案 1、解决方式一 2、解决方式二 上周五,我要改造一个之前从未接触过的 SpringBoot 项目。我用 git 拉下代码后,试图使用 Idea 运行它。但是,Idea 在运行时抛出了一个问题:Error running \\\'Application\\\': Command line is too l

    2023年04月23日
    浏览(30)
  • IDEA:Error running,Command line is too long. 解决方法

    报错如下: 原因是启动命令过长。 解决方法: 1、打开Edit Configurations 2、点击Modify options设置,勾选Shorten command line 3、在Edit Configurations界面下方新增的Shorten command line选项中选择JAR manifest或classpath file 然后 Apply,OK 即可。

    2024年02月01日
    浏览(32)
  • Intellij IDEA运行报Command line is too long的解决办法

    想哭,vue前端运行起来,对应的后端也得起服务。 后端出的这个bug,下面的博客写的第二种方法,完整截图是下面这个。 ​​​​​​​​​​​​​​​​​​​​Intellij IDEA运行报Command line is too long的解决办法 - 知乎 (zhihu.com)​​​​​​​  ​​​​​​​    

    2024年02月14日
    浏览(27)
  • IDEA 启动错误提示:Command line is too long. Shorten command line

    Edit Configurations-configuration-shorten command line none:这是默认选项。IDE不会缩短长类路径。如果命令行超出操作系统限制,则IDEA将无法运行您的应用程序 jar manifest:IDE通过临时classpath.jar传递长类路径。原始类路径在MANIFEST.MF中定义为classpath.jar中的类路径属性 classpath file:IDE将把

    2024年02月02日
    浏览(36)
  • Nginx报错 HTTP 413 Request Entity Too Large(Payload Too Large)解决方案

    上传文件时,请求参数过大,导致超出服务端限制。 客户端发送的实体主体部分比服务器能够或者希望处理的要大。  Nginx默认最大能够上传1MB文件,打开nginx.conf在http{}中,找到server{}设置: client_max_body_size 30m;(配置客户端请求实体最大值) client_body_buffer_size 128k;(配置请

    2024年02月07日
    浏览(43)
  • 启动springboot项目时命令行太长错误解决(Command line is too long)

    刚从git拉取的项目进行启动时报错,说命令行太长。 Error running ‘YudaoServerApplication’: Command line is too long. Shorten command line for YudaoServerApplication or also for Spring Boot default configuration. 1.选择项目配置项 2.选择 Configuration 菜单中的 Shorten command line 下拉框中的 JAR manifest 或者 classpat

    2024年02月12日
    浏览(37)
  • elastic安装报错:max file descriptors [4096] for elasticsearch process is too low, increase to at least

    一、现象 因为 es 不允许使用root用户安装,在使用新建的es用户安装的时候报错如下, max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535] 二、解决办法 将当前用户的软硬限制调大。找到文件 /etc/security/limits.conf ,编辑,在文件的最后追加如下配置:  

    2024年02月11日
    浏览(28)
  • Data too long for column ‘xxxx‘ at row 1 解决办法

    很简单的啦,往下看 Data too long for column ‘xxxx’ at row 1 第一种情况就是很普遍的,xxx字段长度不够 就是用Mybatis映射文件xml,字段匹配顺序错误即 原来很短的一个列,插入了很长的数据 就是数据库字符集的问题 重新设置字符串长度 仔细看一眼sql,就能排错 PS: 前端提出来

    2024年02月07日
    浏览(31)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包