# Nest v6.2.0 Self Referncing Loop

**URL:** <https://discuss.elastic.co/t/nest-v6-2-0-self-referncing-loop/143718>\
**Category:** Elasticsearch\
**Created:** [August 9, 2018, 2:20pm UTC](https://discuss.elastic.co/t/nest-v6-2-0-self-referncing-loop/143718 "2018-08-09T14:20:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Conor\_Malcolm](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@Conor\_Malcolm](https://discuss.elastic.co/u/Conor_Malcolm)\
**Post date:** [August 9, 2018, 2:20pm UTC](https://discuss.elastic.co/t/nest-v6-2-0-self-referncing-loop/143718/1 "2018-08-09T14:20:19Z")

</div>

I am using Nest v6.2.0 to connect to elastic search.

When I am trying to add a document of type A to an index I get a Self Referencing loop error because the object of type A has a property of type B and type B has a property of type A. Both objects of type A & B are database objects.

I can set the ReferenceLoopHandling setting to ReferenceLoopHandling.Ignore on a JsonParser and it can parse the object fine, but I can't seem to send that json string to elastic search. So how can I set the same setting on the Json Parser used by Nest? SO that I can send the object to elastic search and Nest can correctly parse the object without the self referencing loop error.

---

<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:** [August 9, 2018, 11:40pm UTC](https://discuss.elastic.co/t/nest-v6-2-0-self-referncing-loop/143718/2 "2018-08-09T23:40:22Z")

</div>

You may want to use different, simpler POCOs to model the documents that you're sending to Elasticsearch, to avoid potentially large object graphs through self-referencing loops.

You can reference [`Nest.JsonNetSerializer` nuget package](https://www.nuget.org/packages/NEST.JsonNetSerializer/) and [hook up Json.NET as the serializer to use with NEST](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/custom-serialization.html#_jsonnetserializer), configuring the ReferenceLoopHandling property

```auto
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));

var settings = new ConnectionSettings(pool, (builtInSerializer, connectionSettings) =>
    new JsonNetSerializer(builtInSerializer, connectionSettings, () => new JsonSerializerSettings
    {
        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
    }));

var client = new ElasticClient(settings);

```

---

<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:** [September 6, 2018, 11:52pm UTC](https://discuss.elastic.co/t/nest-v6-2-0-self-referncing-loop/143718/3 "2018-09-06T23:52:54Z")

</div>

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