# Elasticsearch-rest-client-5.6.1.jar org.apache.http.ContentTooLongException: entity content is too long \[217056451\] for the configured buffer limit \[104857600\]

**URL:** <https://discuss.elastic.co/t/elasticsearch-rest-client-5-6-1-jar-org-apache-http-contenttoolongexception-entity-content-is-too-long-217056451-for-the-configured-buffer-limit-104857600/101387>\
**Category:** Elasticsearch\
**Created:** [September 21, 2017, 7:48pm UTC](https://discuss.elastic.co/t/elasticsearch-rest-client-5-6-1-jar-org-apache-http-contenttoolongexception-entity-content-is-too-long-217056451-for-the-configured-buffer-limit-104857600/101387 "2017-09-21T19:48:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![iti](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@iti](https://discuss.elastic.co/u/iti)\
**Post date:** [September 21, 2017, 7:48pm UTC](https://discuss.elastic.co/t/elasticsearch-rest-client-5-6-1-jar-org-apache-http-contenttoolongexception-entity-content-is-too-long-217056451-for-the-configured-buffer-limit-104857600/101387/1 "2017-09-21T19:48:38Z")

</div>

I am using REST low level api to query the ES 5.4.0 or 5.5.2 server. and got the following exceptions:  
Anyway to change the bufferLimitBytes?

12:34:50,453 INFO [stdout] (default task-2) org.apache.http.ContentTooLongException: entity content is too long [217056451] for the configured buffer limit [104857600]  
12:34:50,453 INFO [stdout] (default task-2) at org.elasticsearch.client.HeapBufferedAsyncResponseConsumer.onEntityEnclosed(HeapBufferedAsyncResponseConsumer.java:76) ~[elasticsearch-rest-client-5.6.1.jar:5.6.1]  
12:34:50,453 INFO [stdout] (default task-2) at org.apache.http.nio.protocol.AbstractAsyncResponseConsumer.responseReceived(AbstractAsyncResponseConsumer.java:131) ~[httpcore-nio-4.4.5.jar:4.4.5]  
12:34:50,453 INFO [stdout] (default task-2) at org.apache.http.impl.nio.client.MainClientExec.responseReceived(MainClientExec.java:315) ~[httpasyncclient-4.1.2.jar:4.1.2]  
12:34:50,453 INFO [stdout] (default task-2) at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseReceived(DefaultClientExchangeHandlerImpl.java:147) ~[httpasyncclient-4.1.2.jar:4.1.2]  
12:34:50,453 INFO [stdout] (default task-2) at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.responseReceived(HttpAsyncRequestExecutor.java:303) ~[httpcore-nio-4.4.5.jar:4.4.5]  
12:34:50,453 INFO [stdout] (default task-2) at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:255) ~[httpcore-nio-4.4.5.jar:4.4.5]  
12:34:50,453 INFO [stdout] (default task-2) at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81) ~[httpasyncclient-4.1.2.jar:4.1.2]  
12:34:50,453 INFO [stdout] (default task-2) at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39) ~[httpasyncclient-4.1.2.jar:4.1.2]  
12:34:50,453 INFO [stdout] (default task-2) at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114) ~[httpcore-nio-4.4.5.jar:4.4.5]  
12:34:50,453 INFO [stdout] (default task-2) at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162) ~[httpcore-nio-4.4.5.jar:4.4.5]  
12:34:50,453 INFO [stdout] (default task-2) at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337) ~[httpcore-nio-4.4.5.jar:4.4.5]  
12:34:50,453 INFO [stdout] (default task-2) at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315) ~[httpcore-nio-4.4.5.jar:4.4.5]  
12:34:50,453 INFO [stdout] (default task-2) at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276) ~[httpcore-nio-4.4.5.jar:4.4.5]  
12:34:50,453 INFO [stdout] (default task-2) at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104) ~[httpcore-nio-4.4.5.jar:4.4.5]  
12:34:50,453 INFO [stdout] (default task-2) at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:588) ~[httpcore-nio-4.4.5.jar:4.4.5]  
12:34:50,453 INFO [stdout] (default task-2) at java.lang.Thread.run(Thread.java:748) [?:1.8.0\_141]  
12:34:50,453 INFO [stdout] (default task-2) Suppressed: org.apache.http.ContentTooLongException: entity content is too long [217056451] for the configured buffer limit [104857600]

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 21, 2017, 8:09pm UTC](https://discuss.elastic.co/t/elasticsearch-rest-client-5-6-1-jar-org-apache-http-contenttoolongexception-entity-content-is-too-long-217056451-for-the-configured-buffer-limit-104857600/101387/2 "2017-09-21T20:09:10Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

The first question is why are you getting back a so big Response? What kind of query are you running.

To answer your question, have a look at

> <https://github.com/dadoonet/fscrawler/issues/432#issuecomment-328764901>

---

<div class="post-metadata">

**Author:** ![iti](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@iti](https://discuss.elastic.co/u/iti)\
**Post date:** [September 22, 2017, 6:56am UTC](https://discuss.elastic.co/t/elasticsearch-rest-client-5-6-1-jar-org-apache-http-contenttoolongexception-entity-content-is-too-long-217056451-for-the-configured-buffer-limit-104857600/101387/3 "2017-09-22T06:56:49Z")

</div>

The above link does not help. I am really retrieving that much data.  
I am retrieving 180k documents (setting the index.max\_result\_window=1Million). So, query size is set at 1,000,000. Query result \>200MB is normal. If I set the query size=80k. Result is just below 100MB, everything works fine. I know I can use scroll api to get the data piece by piece. But this is just an occasional thing. If the buffersize is not default to 100MB and is settable, it would be nice.

I am using low level REST api to do the query, any better way to fetch millions of records in one shot?  
Thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 22, 2017, 7:38am UTC](https://discuss.elastic.co/t/elasticsearch-rest-client-5-6-1-jar-org-apache-http-contenttoolongexception-entity-content-is-too-long-217056451-for-the-configured-buffer-limit-104857600/101387/4 "2017-09-22T07:38:00Z")

</div>

You definitely need to use scroll. By default elasticsearch does not support more than 10000 results (from+size) for very good reasons like cluster stability, OOM...

---

<div class="post-metadata">

**Author:** ![iti](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@iti](https://discuss.elastic.co/u/iti)\
**Post date:** [September 22, 2017, 5:05pm UTC](https://discuss.elastic.co/t/elasticsearch-rest-client-5-6-1-jar-org-apache-http-contenttoolongexception-entity-content-is-too-long-217056451-for-the-configured-buffer-limit-104857600/101387/5 "2017-09-22T17:05:43Z")

</div>

I understand the 10k limit, that is why I increase the default to 1M. If ES lets people change the default of query results, then the buffer size should be changeable also, otherwise bufferLimitBytes set(100M) in org.elasticsearch.client.HeapBufferedAsyncResponseConsumer is the real limit:)  
Thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 22, 2017, 5:52pm UTC](https://discuss.elastic.co/t/elasticsearch-rest-client-5-6-1-jar-org-apache-http-contenttoolongexception-entity-content-is-too-long-217056451-for-the-configured-buffer-limit-104857600/101387/6 "2017-09-22T17:52:31Z")

</div>

I'd not do that.

But if you really want to overload your data nodes and your client, up to you.

Did you read the workaround that Tanguy mentioned in the issue I linked to?

Specifically that class:

> <https://github.com/elastic/elasticsearch/blob/706067211ae880bbe4669286ee976552e8a60446/client/rest/src/main/java/org/elasticsearch/client/HttpAsyncResponseConsumerFactory.java#L49-L64>

---

<div class="post-metadata">

**Author:** ![iti](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@iti](https://discuss.elastic.co/u/iti)\
**Post date:** [September 22, 2017, 8:25pm UTC](https://discuss.elastic.co/t/elasticsearch-rest-client-5-6-1-jar-org-apache-http-contenttoolongexception-entity-content-is-too-long-217056451-for-the-configured-buffer-limit-104857600/101387/7 "2017-09-22T20:25:55Z")

</div>

Nice. I did not notice that ES has the following function:

```auto
Response performRequest(String method, String endpoint,
                        Map<String, String> params,
                        HttpEntity entity,
                        HttpAsyncResponseConsumerFactory responseConsumerFactory,
                        Header... headers)
    throws IOException;

```

This makes the buffer size configurable  
This is what I did:

```auto
 //Overiding the 100MB Buffer Limit to 1GB
response = client.performRequest("GET", request.getIndexName() + typesString + "/_search", new HashMap<>(),
					new NStringEntity(queryString, ContentType.APPLICATION_JSON),
					new HeapBufferedResponseConsumerFactory(1024 * 1024 * 1024));

```

It is working now. Thanks for the help @dadoonet

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 20, 2017, 8:25pm UTC](https://discuss.elastic.co/t/elasticsearch-rest-client-5-6-1-jar-org-apache-http-contenttoolongexception-entity-content-is-too-long-217056451-for-the-configured-buffer-limit-104857600/101387/8 "2017-10-20T20:25:56Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
