# 413- Request too large exception

**URL:** <https://discuss.elastic.co/t/413-request-too-large-exception/101562>\
**Category:** Elasticsearch\
**Created:** [September 23, 2017, 12:18pm UTC](https://discuss.elastic.co/t/413-request-too-large-exception/101562 "2017-09-23T12:18:38Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![dimalini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dimalini/32/22448_2.png) [@dimalini](https://discuss.elastic.co/u/dimalini)\
**Post date:** [September 23, 2017, 12:18pm UTC](https://discuss.elastic.co/t/413-request-too-large-exception/101562/1 "2017-09-23T12:18:38Z")

</div>

Hi,  
In our regular indexing scenario when using Bulk index API we are constantly hitting into "HTTP Status Code - 413, Exception - System.Net.WebException: The remote server returned an error: (413) Request Entity Too Large."

We do control the batch size before sending the request that is definitely lesser than 100mb. I see across posts it is recommended to increase the http.max\_content\_length to a greater value to address this.

Note: we are using ES5.x and NEST 2.x  
In addition to the batch request that is originally being sent is there any additional payload that gets added by NEST? Or could someone suggest the best way to debug this issue and identify the root cause?

Thanks in advance!  
~Divya Malini

---

<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 21, 2017, 12:19pm UTC](https://discuss.elastic.co/t/413-request-too-large-exception/101562/2 "2017-10-21T12:19:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 2, 2017, 9:01pm UTC](https://discuss.elastic.co/t/413-request-too-large-exception/101562/3 "2017-11-02T21:01:35Z")

</div>



---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 2, 2017, 9:01pm UTC](https://discuss.elastic.co/t/413-request-too-large-exception/101562/4 "2017-11-02T21:01:41Z")

</div>

What do the Elasticsearch logs show at this time?

---

<div class="post-metadata">

**Author:** ![dimalini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dimalini/32/22448_2.png) [@dimalini](https://discuss.elastic.co/u/dimalini)\
**Post date:** [November 3, 2017, 11:58am UTC](https://discuss.elastic.co/t/413-request-too-large-exception/101562/5 "2017-11-03T11:58:42Z")

</div>

The ES logs file doesn't capture this exception or any detail related to the request that caused this exception. It is the InnerException message from ESResponse that has the following

ES Exception: HTTP Status Code - 413, Exception - System.Net.WebException: The remote server returned an error: (413) Request Entity Too Large.  
at System.Net.HttpWebRequest.GetResponse()  
at Elasticsearch.Net.HttpConnection.Request[TReturn](RequestData requestData) in C:\Repos\GitHub\_elastic\_elasticsearch-net\src\[Elasticsearch.Net](http://Elasticsearch.Net)\Connection\HttpConnection.cs:line 140.

---

<div class="post-metadata">

**Author:** ![dimalini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dimalini/32/22448_2.png) [@dimalini](https://discuss.elastic.co/u/dimalini)\
**Post date:** [November 6, 2017, 5:39am UTC](https://discuss.elastic.co/t/413-request-too-large-exception/101562/6 "2017-11-06T05:39:52Z")

</div>

-\> Could someone help understand what all cases ES throws 413 or content length is the only possibility?  
-\> Is there any ideal way through NEST that you recommend to detect the physical size of the request before being sent to ES?  
-\> Currently ES log doesn't capture any data regd the 413, anyway to enable it?

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [November 6, 2017, 6:25am UTC](https://discuss.elastic.co/t/413-request-too-large-exception/101562/7 "2017-11-06T06:25:23Z")

</div>

> [@dimalini](#):
>
> Note: we are using ES5.x and NEST 2.x

I would recommend upgrading to NEST 5.x; NEST 2.x is not compatible with Elasticsearch 5.x. Whilst it may work for the most part, it is not tested or supported against it as there are known breaking changes in Elasticsearch that are reflected in API changes in the client.

> [@dimalini](#):
>
> We do control the batch size before sending the request that is definitely lesser than 100mb.

How are you currently ensuring this? One way that you could measure this to get an understanding of how big your requests are would be to [set up an `Action<IApiCallDetails>` delegate in `.OnRequestCompleted()`](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/logging-with-on-request-completed.html) in conjunction with `.DisableDirectStreaming()`, and write the request to disk, and check the size of the files.

---

<div class="post-metadata">

**Author:** ![dimalini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dimalini/32/22448_2.png) [@dimalini](https://discuss.elastic.co/u/dimalini)\
**Post date:** [November 13, 2017, 5:12am UTC](https://discuss.elastic.co/t/413-request-too-large-exception/101562/8 "2017-11-13T05:12:05Z")

</div>

Hey Russ,  
Sorry for the late reply. I will try this suggestion out and get back here. Thanks!

---

<div class="post-metadata">

**Author:** ![dimalini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dimalini/32/22448_2.png) [@dimalini](https://discuss.elastic.co/u/dimalini)\
**Post date:** [March 31, 2018, 5:47am UTC](https://discuss.elastic.co/t/413-request-too-large-exception/101562/9 "2018-03-31T05:47:40Z")

</div>

Hi Russ,  
I tried this suggestion and realized that the requestbody size was exceeding the limit set with max\_content\_length. The difference was the jsonified request was more than the calculations we did before creating the jsonified string.

Now, is there anyway to get "apiCallDetails. **ResponseBodyInBytes**" value before we actually make the bulk call ?

-Divya

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [March 31, 2018, 5:57am UTC](https://discuss.elastic.co/t/413-request-too-large-exception/101562/10 "2018-03-31T05:57:02Z")

</div>

> [@dimalini](#):
>
> Now, is there anyway to get "apiCallDetails.ResponseBodyInBytes" value before we actually make the bulk call ?

This wouldn't be possible, as the response body bytes will only be known _after_ the request has been processed by Elasticsearch.

---

<div class="post-metadata">

**Author:** ![dimalini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dimalini/32/22448_2.png) [@dimalini](https://discuss.elastic.co/u/dimalini)\
**Post date:** [March 31, 2018, 9:25am UTC](https://discuss.elastic.co/t/413-request-too-large-exception/101562/11 "2018-03-31T09:25:18Z")

</div>

Okay, got it. Thank you!!

---

<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:** [November 4, 2022, 4:59am UTC](https://discuss.elastic.co/t/413-request-too-large-exception/101562/12 "2022-11-04T04:59:09Z")

</div>


