# The maximum configured depth of 64 has been exceeded. Cannot read next JSON object

**URL:** <https://discuss.elastic.co/t/the-maximum-configured-depth-of-64-has-been-exceeded-cannot-read-next-json-object/378954>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [June 6, 2025, 1:47pm UTC](https://discuss.elastic.co/t/the-maximum-configured-depth-of-64-has-been-exceeded-cannot-read-next-json-object/378954 "2025-06-06T13:47:14Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikos\_Levogiannis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikos_levogiannis/32/137952_2.png) [@Nikos\_Levogiannis](https://discuss.elastic.co/u/Nikos_Levogiannis)\
**Post date:** [June 6, 2025, 1:47pm UTC](https://discuss.elastic.co/t/the-maximum-configured-depth-of-64-has-been-exceeded-cannot-read-next-json-object/378954/1 "2025-06-06T13:47:14Z")

</div>

I am trying to make a search request using the new ElasticsearchClient 8.18 (C# .net) with a high number of aggregations and I get the error :  
The maximum configured depth of 64 has been exceeded. Cannot read next JSON object

Is there a way to increase the max depth of the System.Text.Json.JsonSerializer above 64 so that my request can pass??

I can't seem to find a way,

Thank you

---

<div class="post-metadata">

**Author:** ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)\
**Post date:** [June 6, 2025, 2:23pm UTC](https://discuss.elastic.co/t/the-maximum-configured-depth-of-64-has-been-exceeded-cannot-read-next-json-object/378954/2 "2025-06-06T14:23:21Z")

</div>

Hi @Nikos_Levogiannis ,

you can configure the `JsonSerializerOptions` for the serializer that is used for your documents:

> **[Source serialization | Elasticsearch .NET Client \[8.18\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/net-api/8.18/source-serialization.html#configuring-custom-jsonserializeroptions)**

There currently is no way to modify the internal serializer that is used for Elasticsearch specific types.

A depth of 64 is very very unusual. Would you mind sharing the JSON response (e.g. by sending the same search request using CURL / Kibana Dev Tools Console, etc.)?

---

<div class="post-metadata">

**Author:** ![Nikos\_Levogiannis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikos_levogiannis/32/137952_2.png) [@Nikos\_Levogiannis](https://discuss.elastic.co/u/Nikos_Levogiannis)\
**Post date:** [June 6, 2025, 2:28pm UTC](https://discuss.elastic.co/t/the-maximum-configured-depth-of-64-has-been-exceeded-cannot-read-next-json-object/378954/3 "2025-06-06T14:28:28Z")

</div>

Hi @flobernd !

Thanks for replying. I tried to configure the JsonSerialization option by setting a MaxDepth of 256 but I keep getting the error that exceeds 64. I can even see in my Client object that the MaxDepth is correctly set to 256.

Other than that I believe I am getting the error because of my aggregations json which I believe is close to the limit. I can post this if youwant. The problem is that the creation of the aggregations is dynamic and it could go much higher than 64...

---

<div class="post-metadata">

**Author:** ![Nikos\_Levogiannis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikos_levogiannis/32/137952_2.png) [@Nikos\_Levogiannis](https://discuss.elastic.co/u/Nikos_Levogiannis)\
**Post date:** [June 6, 2025, 2:41pm UTC](https://discuss.elastic.co/t/the-maximum-configured-depth-of-64-has-been-exceeded-cannot-read-next-json-object/378954/4 "2025-06-06T14:41:47Z")

</div>

Hey @flobernd !

I use the following to increase the MaxDepth limit and it does not work. (I can see in debug mode that the limit is set). I use 8.18.

```auto
        static void ConfigureOptions(JsonSerializerOptions o)
        {
            o.MaxDepth = 256;
        }

            var pool = new SingleNodePool(new Uri(ElasticUrl!));
            var settings = new ElasticsearchClientSettings(pool, sourceSerializer: (defaultSerializer, settings) =>
                    new DefaultSourceSerializer(settings, ConfigureOptions))
                .CertificateFingerprint(CertificateFingerprint!)
                .Authentication(new BasicAuthentication("elastic", ElasticPassword!))
                .RequestTimeout(TimeSpan.FromMinutes(30));
            Client = new ElasticsearchClient(settings);

```

Is this a bug of the client?

Also my aggregations json is as follows:

```auto
  "aggregations": {
    "Day": {
      "aggregations": {
        "Date": {
          "aggregations": {
            "OrderName": {
              "aggregations": {
                "OrderStatus": {
                  "aggregations": {
                    "Gateway": {
                      "aggregations": {
                        "FinancialStatus": {
                          "aggregations": {
                            "FulfillmentStatus": {
                              "aggregations": {
                                "Cancelled": {
                                  "aggregations": {
                                    "SKU": {
                                      "aggregations": {
                                        "Vendor": {
                                          "aggregations": {
                                            "ProductTitle": {
                                              "aggregations": {
                                                "ProductType": {
                                                  "aggregations": {
                                                    "OrderNote": {
                                                      "aggregations": {
                                                        "ShippingZip": {
                                                          "aggregations": {
                                                            "ShippingCountry": {
                                                              "aggregations": {
                                                                "ShippingProvince": {
                                                                  "aggregations": {
                                                                    "CustomerName": {
                                                                      "aggregations": {
                                                                        "SalesChannelName": {
                                                                          "aggregations": {
                                                                            "DeliveryMethod": {
                                                                              "aggregations": {
                                                                                "OrderTags": {
                                                                                  "aggregations": {
                                                                                    "ProductId": {
                                                                                      "aggregations": {
                                                                                        "OrderId": {
                                                                                          "aggregations": {
                                                                                            "StoreId": {
                                                                                              "aggregations": {
                                                                                                "LineItemReturnedQuantity": {
                                                                                                  "sum": {
                                                                                                    "field": "lineItemReturnedQuantity"
                                                                                                  }
                                                                                                },
                                                                                                "LineItemOrderedQuantity": {
                                                                                                  "sum": {
                                                                                                    "field": "lineItemOrderedQuantity"
                                                                                                  }
                                                                                                },
                                                                                                .....
max depth here

```

I would like to clarify that the JsonSerialization override does not work, and try to find a workaround...

By the way if I make a call with the low level elasticsearch client and push the query as raw string then the request is successful, meaning that the problem is on the query end. The serializer finds it to exceed the 64 (which can not be overridden) limit.

Thank you

---

<div class="post-metadata">

**Author:** ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)\
**Post date:** [June 7, 2025, 5:16pm UTC](https://discuss.elastic.co/t/the-maximum-configured-depth-of-64-has-been-exceeded-cannot-read-next-json-object/378954/5 "2025-06-07T17:16:23Z")

</div>

Hi @Nikos_Levogiannis ,

this is quite an uncommon case (and I expect performance not to be great - but that’s a different story).

You are right that we would have to modify the allowed depth for the internal serializer. We currently don’t allow to tamper with this instance since we make lots of assumptions in our custom (de-)serialization code which we could no longer rely on, if the user is allowed to modify the internal serializer.

I could probably increase the limit to 128 or some other sufficiently high value, if that helps. Otherwise you could use reflection to modify the internal serializer instance.

---

<div class="post-metadata">

**Author:** ![Nikos\_Levogiannis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikos_levogiannis/32/137952_2.png) [@Nikos\_Levogiannis](https://discuss.elastic.co/u/Nikos_Levogiannis)\
**Post date:** [June 8, 2025, 8:42am UTC](https://discuss.elastic.co/t/the-maximum-configured-depth-of-64-has-been-exceeded-cannot-read-next-json-object/378954/6 "2025-06-08T08:42:55Z")

</div>

Hi @flobernd !

and thanks for the reply...

if you could increase it to at least 256 that would be great.

Also, if you could share a solution to use reflection to increase it manually that would be great also...

I have created a software that depends solely on elasticsearch and have 500+ customers using it. I am working on a workaround to use sibling aggregations when possible, but there is a chance that the user can select combinations that go past the 64 maxdepth...

Looking forward to your reply,

Thanks again!

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 8, 2025, 10:51am UTC](https://discuss.elastic.co/t/the-maximum-configured-depth-of-64-has-been-exceeded-cannot-read-next-json-object/378954/7 "2025-06-08T10:51:53Z")

</div>

Make sure you test it with such large aggregation nesting as it can cause high memory usage.

---

<div class="post-metadata">

**Author:** ![Nikos\_Levogiannis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikos_levogiannis/32/137952_2.png) [@Nikos\_Levogiannis](https://discuss.elastic.co/u/Nikos_Levogiannis)\
**Post date:** [June 11, 2025, 9:21am UTC](https://discuss.elastic.co/t/the-maximum-configured-depth-of-64-has-been-exceeded-cannot-read-next-json-object/378954/8 "2025-06-11T09:21:34Z")

</div>

Hi @flobernd !

any new on the below?

if you could increase it to at least 256 that would be great.

Also, if you could share a solution to use reflection to increase it manually that would be great also...

I have created a software that depends solely on elasticsearch and have 500+ customers using it. I am working on a workaround to use sibling aggregations when possible, but there is a chance that the user can select combinations that go past the 64 maxdepth...

Looking forward to your reply,

Thanks again!

---

<div class="post-metadata">

**Author:** ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)\
**Post date:** [June 11, 2025, 9:56am UTC](https://discuss.elastic.co/t/the-maximum-configured-depth-of-64-has-been-exceeded-cannot-read-next-json-object/378954/9 "2025-06-11T09:56:19Z")

</div>

Hi @Nikos_Levogiannis ,

we have discussed this internally and I'll increase the depth to 256 or even 512. This change will be included in the next release (probably next week).

---

<div class="post-metadata">

**Author:** ![Nikos\_Levogiannis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikos_levogiannis/32/137952_2.png) [@Nikos\_Levogiannis](https://discuss.elastic.co/u/Nikos_Levogiannis)\
**Post date:** [June 11, 2025, 10:29am UTC](https://discuss.elastic.co/t/the-maximum-configured-depth-of-64-has-been-exceeded-cannot-read-next-json-object/378954/10 "2025-06-11T10:29:53Z")

</div>

Sounds great! 512 would be great..

Please let me know when you do it!

Thank you very very much for your responsiveness!

---

<div class="post-metadata">

**Author:** ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)\
**Post date:** [June 14, 2025, 7:45am UTC](https://discuss.elastic.co/t/the-maximum-configured-depth-of-64-has-been-exceeded-cannot-read-next-json-object/378954/11 "2025-06-14T07:45:32Z")

</div>

Changed to 512 in 8.18.2.
