Java org.apache.http.ContentTooLongException:实体内容太长[105539255],无法满足配置的缓冲区限制[104857600]
我正在尝试从我的索引(ElasticSearch)中获取索引PDF文档。我已经使用ingest attachment processor插件为我的pdf文档编制了索引。它总共有2500份文档被编入索引,并附有PDF附件 现在我通过搜索PDF的内容来获取这些PDF,并得到以下错误Java org.apache.http.ContentTooLongException:实体内容太长[105539255],无法满足配置的缓冲区限制[104857600],java,elasticsearch,kibana,elastic-stack,Java,elasticsearch,Kibana,Elastic Stack,我正在尝试从我的索引(ElasticSearch)中获取索引PDF文档。我已经使用ingest attachment processor插件为我的pdf文档编制了索引。它总共有2500份文档被编入索引,并附有PDF附件 现在我通过搜索PDF的内容来获取这些PDF,并得到以下错误 org.apache.http.ContentTooLongException: entity content is too long [105539255] for the configured buffer limi
org.apache.http.ContentTooLongException: entity content is too long [105539255] 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:131)
at org.apache.http.impl.nio.client.MainClientExec.responseReceived(MainClientExec.java:315)
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseReceived(DefaultClientExchangeHandlerImpl.java:147)
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.responseReceived(HttpAsyncRequestExecutor.java:303)
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:588)
at java.lang.Thread.run(Thread.java:748)
Exception in thread "main" java.lang.NullPointerException
at com.es.utility.DocumentSearch.main(DocumentSearch.java:88)
请查找我的Java API代码以从ElasticSearch获取文档
private final static String ATTACHMENT = "document_attachment";
private final static String TYPE = "doc";
public static void main(String args[])
{
RestHighLevelClient restHighLevelClient = null;
try {
restHighLevelClient = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http"),
new HttpHost("localhost", 9201, "http")));
} catch (Exception e) {
System.out.println(e.getMessage());
}
SearchRequest contentSearchRequest = new SearchRequest(ATTACHMENT);
SearchSourceBuilder contentSearchSourceBuilder = new SearchSourceBuilder();
contentSearchRequest.types(TYPE);
QueryBuilder attachmentQB = QueryBuilders.matchQuery("attachment.content", "activa");
contentSearchSourceBuilder.query(attachmentQB);
contentSearchSourceBuilder.size(50);
contentSearchRequest.source(contentSearchSourceBuilder);
SearchResponse contentSearchResponse = null;
System.out.println("Request --->"+contentSearchRequest.toString());
try {
contentSearchResponse = restHighLevelClient.search(contentSearchRequest);
} catch (IOException e) {
e.getLocalizedMessage();
}
try {
System.out.println("Response --->"+restHighLevelClient.search(contentSearchRequest)); // am printing the mentioned error from this line.
} catch (IOException e) {
e.printStackTrace();
}
SearchHit[] contentSearchHits = contentSearchResponse.getHits().getHits();
long contenttotalHits=contentSearchResponse.getHits().totalHits;
System.out.println("condition Total Hits --->"+contenttotalHits);
我正在使用ElasticSearch 6.2.3版您需要增加
ElasticSearch.yml
配置文件中的http.max\u content\u length
默认情况下,它被设置为100MB(100*1024*1024=104857600),因此您可能需要将其设置得稍高一点
更新
这实际上是一个不同的问题,对此进行了解释。基本上,默认的HttpAsyncResponseConsumerFactory在堆内存中缓冲整个响应体,但默认情况下只有100mb。解决方法是为该缓冲区配置另一个大小,但您唯一的选择是使用低级REST客户机。在ES 7中,您可以使用名为RequestOptions
的类在高级REST客户机上执行此操作,但该类尚未发布
long BUFFER_SIZE = 120 * 1024 * 1024; <---- set buffer to 120MB instead of 100MB
Map<String, String> params = Collections.emptyMap();
HttpEntity entity = new NStringEntity(contentSearchSourceBuilder.toString(), ContentType.APPLICATION_JSON);
HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory consumerFactory =
new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(BUFFER_SIZE);
Response response = restClient.performRequest("GET", "/document_attachment/doc/_search", params, entity, consumerFactory);
long BUFFER_SIZE=120*1024*1024;我在elasticsearch.yml
文件http.max\u content\u length:200mb
中做了更改,然后通过services.msc重新启动了elasticsearch,但仍然收到相同的错误消息。是否需要执行其他操作。?此条目在elasticsearch.yml
文件中不可用。我在文件末尾手动添加了这一行http.max\u content\u length:200MB
。(作为最后一行)。即使它不工作。你有什么想法吗?。如何从elasticsearch.yml
配置http.max\u content\u length:200mb
文件不适用于ES版本6.2.3。这实际上是一个不同的问题,我正在研究它。我们对此问题有任何解决方法吗?现在我正在使用RestHighLevelClient
,我们是否有其他客户进行沟通。