# Parent/Child relationships

**URL:** <https://discuss.elastic.co/t/parent-child-relationships/256475>\
**Category:** Elasticsearch\
**Created:** [November 24, 2020, 9:25am UTC](https://discuss.elastic.co/t/parent-child-relationships/256475 "2020-11-24T09:25:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SergioRodenas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sergiorodenas/32/79590_2.png) [@SergioRodenas](https://discuss.elastic.co/u/SergioRodenas)\
**Post date:** [November 24, 2020, 9:25am UTC](https://discuss.elastic.co/t/parent-child-relationships/256475/1 "2020-11-24T09:25:44Z")

</div>

Hi I'm using the example from the NEST documentation, [https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/parent-child-relationships.html](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/parent-child-relationships.html)

The index has been created and the mapping too, but the documents are not inserted.

 ![mapping](https://us1.discourse-cdn.com/elastic/original/3X/c/a/ca749d761696845685d9ccc107cfc8aa96f28395.png)

 ![search](https://us1.discourse-cdn.com/elastic/original/3X/f/6/f6d60cd4667e9057643c905b27c1227c49b65ef1.png)

```
class Program
{
    public abstract class MyDocument
    {
        public int Id { get; set; }
        public JoinField MyJoinField { get; set; }
    }

    public class MyParent : MyDocument
    {
        [Text]
        public string ParentProperty { get; set; }
    }

    public class MyChild : MyDocument
    {
        [Text]
        public string ChildProperty { get; set; }
    }

    static void Main(string[] args)
    {
        var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));

        var connectionSettings = new ConnectionSettings(connectionPool)
            .DefaultMappingFor<MyDocument>(m => m.IndexName("indexparentchild"))
            .DefaultMappingFor<MyChild>(m => m.IndexName("indexparentchild"))
            .DefaultMappingFor<MyParent>(m => m.IndexName("indexparentchild").RelationName("parent"));

        var client = new ElasticClient(connectionSettings);

        var createIndexResponse = client.Indices.Create("indexparentchild", c => c
            .Index<MyDocument>()
            .Map<MyDocument>(m => m
                .RoutingField(r => r.Required())
                .AutoMap<MyParent>()
                .AutoMap<MyChild>()
                .Properties(props => props
                    .Join(j => j
                        .Name(p => p.MyJoinField)
                        .Relations(r => r
                            .Join<MyParent, MyChild>()
                        )
                    )
                )
            )
        );

        var parentDocument = new MyParent
        {
            Id = 1,
            ParentProperty = "a parent prop",
            MyJoinField = JoinField.Root<MyParent>()
        };

        parentDocument = new MyParent
        {
            Id = 1,
            ParentProperty = "a parent prop",
            MyJoinField = typeof(MyParent)
        };

        parentDocument = new MyParent
        {
            Id = 1,
            ParentProperty = "a parent prop",
            MyJoinField = "myparent"
        };

        var indexParent = client.IndexDocument(parentDocument);

        var indexChild = client.IndexDocument(new MyChild
        {
            MyJoinField = JoinField.Link<MyChild, MyParent>(parentDocument)
        });

        indexChild = client.IndexDocument(new MyChild
        {
            Id = 2,
            MyJoinField = JoinField.Link<MyChild>(1)
        });
    }
}

```

I'm using:

- [docker.elastic.co/kibana/kibana:7.9.3](http://docker.elastic.co/kibana/kibana:7.9.3)
- [docker.elastic.co/elasticsearch/elasticsearch:7.9.3](http://docker.elastic.co/elasticsearch/elasticsearch:7.9.3)
- Visual Studio Community 2019
- Console application with C#
- NEST 7.10.0

any idea? Thanks.

---

<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:** [December 22, 2020, 9:26am UTC](https://discuss.elastic.co/t/parent-child-relationships/256475/2 "2020-12-22T09:26:05Z")

</div>

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