org.apache.http.ContentTooLongException:实体内容对于配置的缓冲区限制 [104857600] 来说太长 [158924648]

问题描述 投票:0回答:1

我的服务执行弹性搜索查询时遇到附加错误。

这是错误日志:

[ERROR] [ZScheduler-1] (Logs.scala:32) - Failed executing elasticSearch query
com.sksamuel.elastic4s.http.JavaClientExceptionWrapper: org.apache.http.ContentTooLongException: entity content is too long [158924647] for the configured buffer limit [104857600]
    at com.sksamuel.elastic4s.http.JavaClient$$anon$1.onFailure(JavaClient.scala:70)
    at org.elasticsearch.client.RestClient$FailureTrackingResponseListener.onDefinitiveFailure(RestClient.java:668)
    at org.elasticsearch.client.RestClient$1.failed(RestClient.java:417)
    at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:137)
    at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.executionFailed(DefaultClientExchangeHandlerImpl.java:101)
    at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.failed(AbstractClientExchangeHandler.java:426)
    at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.exception(HttpAsyncRequestExecutor.java:163)
    at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:276)
    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.base/java.lang.Thread.run(Unknown Source)
Caused by: org.apache.http.ContentTooLongException: entity content is too long [158924647] 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)
    ... 10 more

我尝试使用此解决方案来解决此问题文本 (

HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory consumerFactory = new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(BUFFER_SIZE);
) 但我在尝试以客户端在我的代码中实现的方式来适应它时遇到了麻烦, 它正在使用
JavaClient
apply 实现,其中已经返回
JavaClient
。 这意味着我无法访问该函数内的
RestClient
构建器,而该函数确实可以访问
HeapBufferedResponseConsumerFactory

我对弹性用法很陌生,这不是我的代码,所以我希望做一些可能的改变,有人可以帮我解决这个问题吗?

这是弹性客户端构建器,我希望将缓冲区参数配置添加到:

  def createElasticClient(elasticUrl: String, credentials: Credentials): ElasticClient = {
    ElasticClient(
      JavaClient(
        ElasticProperties(elasticUrl),
        (requestConfigBuilder: RequestConfig.Builder) =>
          requestConfigBuilder
            .setSocketTimeout(INFINITE_SOCKET_TIMEOUT)
            .setConnectTimeout(CONNECTION_TIMEOUT),
        (httpClientBuilder: HttpAsyncClientBuilder) => {
          httpClientBuilder.setKeepAliveStrategy((_, _) => CONNECTION_KEEP_ALIVE_MS)
          httpClientBuilder.setDefaultCredentialsProvider(getCredentials(credentials))
        }
      )
    )
  }
scala elasticsearch elastic4s
1个回答
0
投票

您应该更改“http.max_content_length”,因为默认值为 100 MB

这里是一些文档:https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-http.html

© www.soinside.com 2019 - 2024. All rights reserved.