# Trying to follow can't follow instructions on Parent/Child relationships

**URL:** <https://discuss.elastic.co/t/trying-to-follow-cant-follow-instructions-on-parent-child-relationships/276596>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [June 22, 2021, 2:02am UTC](https://discuss.elastic.co/t/trying-to-follow-cant-follow-instructions-on-parent-child-relationships/276596 "2021-06-22T02:02:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bill\_d](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bill_d/32/90623_2.png) [@bill\_d](https://discuss.elastic.co/u/bill_d)\
**Post date:** [June 22, 2021, 2:02am UTC](https://discuss.elastic.co/t/trying-to-follow-cant-follow-instructions-on-parent-child-relationships/276596/1 "2021-06-22T02:02:36Z")

</div>

I'm following the example on this page: [Parent/Child relationships | Elasticsearch.Net and NEST: the .NET clients [7.x] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/net-api/7.x/parent-child-relationships.html). My program fails indexing the parent, with: `ServerError: Type: routing_missing_exception Reason: "routing is required for [index]/[_doc]/[1]"`

I'm using elasticsearch 7.10.2 in a container and NEST 7.10.0, running in a .net 5 command line program. The code is below.  
I assume that either: there is something different about my code and the documentation that I've missed OR something is missing from the documentation.

Thanks for any pointers or suggestions.

```auto
using System;
using System.Diagnostics;
using Elasticsearch.Net;
using Nest;

namespace elastic_tester
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Trying to follow https://www.elastic.co/guide/en/elasticsearch/client/net-api/7.x/parent-child-relationships.html");

            var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
            var connectionSettings = new ConnectionSettings(connectionPool)
                .DefaultMappingFor<MyDocument>(m => m
                    .IndexName("index"))
                .DefaultMappingFor<MyChild>(m => m
                    .IndexName("index"))
                .DefaultMappingFor<MyParent>(m => m
                    .IndexName("index")
// .RoutingProperty(rp => rp.Id)
                    .RelationName("parent"))
                .DisableDirectStreaming(true)
                .PrettyJson();

            var client = new ElasticClient(connectionSettings);

            var clusterHealth = client.Cluster.Health();
            Console.WriteLine($"Running elasticsearch cluster: '{clusterHealth.ClusterName}', status: {clusterHealth.Status}");

            var createIndexResponse = client.Indices
                .Create("index", 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>() ) ) ) ) );

            Debug.Assert(createIndexResponse.Acknowledged && createIndexResponse.IsValid);
            Console.WriteLine($"Created index named {createIndexResponse.Index}");

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

            // with elasticsearch server 7.10.2 and NEST 7.10.0
            // I get a routing exception
            var indexResponse = client.IndexDocument(parentDocument);
            Console.WriteLine(indexResponse.DebugInformation);
            Debug.Assert(indexResponse.IsValid);
        }
    }

    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; }
    }
}

```

---

<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:** [June 22, 2021, 2:04am UTC](https://discuss.elastic.co/t/trying-to-follow-cant-follow-instructions-on-parent-child-relationships/276596/2 "2021-06-22T02:04:07Z")

</div>

Welcome to our community! 😃

I don't know NEST, but the first thing I would recommend is using the documentation for your version of Elasticsearch. 7.X is master, which will contain things that have not been released, or things that have changed, so should not be used for what you are doing.

---

<div class="post-metadata">

**Author:** ![bill\_d](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bill_d/32/90623_2.png) [@bill\_d](https://discuss.elastic.co/u/bill_d)\
**Post date:** [June 22, 2021, 2:15am UTC](https://discuss.elastic.co/t/trying-to-follow-cant-follow-instructions-on-parent-child-relationships/276596/3 "2021-06-22T02:15:15Z")

</div>

> [@warkolm](#):
>
> ster, which will contain things that have not been released, or things that have changed, so should not be used for what

Thanks for the idea! While the main elasticsearch documentation is split into many versions (major, minor), the NEST library doc just has these  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/2/829c1c5442b37019988f22bdba5fa527790db139.png)

After selecting 'other versions' it looks like this:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/a/facde308c44fa495732558f1465101e21038a68d.png)

So I think 7.x is the closest to the version that I'm using. Right?

---

<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:** [June 22, 2021, 2:16am UTC](https://discuss.elastic.co/t/trying-to-follow-cant-follow-instructions-on-parent-child-relationships/276596/4 "2021-06-22T02:16:58Z")

</div>

Ah ok, I guess that documentation is structured a little differently to the product set.

---

<div class="post-metadata">

**Author:** ![bill\_d](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bill_d/32/90623_2.png) [@bill\_d](https://discuss.elastic.co/u/bill_d)\
**Post date:** [June 22, 2021, 2:20am UTC](https://discuss.elastic.co/t/trying-to-follow-cant-follow-instructions-on-parent-child-relationships/276596/5 "2021-06-22T02:20:42Z")

</div>

Meant to include the output:

```auto
Trying to follow https://www.elastic.co/guide/en/elasticsearch/client/net-api/7.x/parent-child-relationships.html
Running elasticsearch cluster: 'docker-cluster', status: Yellow
Created index named index
Invalid NEST response built from a unsuccessful (400) low level call on PUT: /index/_doc/1?pretty=true
# Audit trail of this API call:
 - [1] BadResponse: Node: http://localhost:9200/ Took: 00:00:00.0435007
# OriginalException: Elasticsearch.Net.ElasticsearchClientException: Request failed to execute. Call: Status code 400 from: PUT /index/_doc/1?pretty=true. ServerError: Type: routing_missing_exception
 Reason: "routing is required for [index]/[_doc]/[1]"
# Request:
{"parentProperty":"a parent property value","id":1,"myJoinField":"parent"}
# Response:
{
  "error" : {
    "root_cause" : [
      {
        "type" : "routing_missing_exception",
        "reason" : "routing is required for [index]/[_doc]/[1]",
        "index_uuid" : "_na_",
        "index" : "index"
      }
    ],
    "type" : "routing_missing_exception",
    "reason" : "routing is required for [index]/[_doc]/[1]",
    "index_uuid" : "_na_",
    "index" : "index"
  },
  "status" : 400
}

```

---

<div class="post-metadata">

**Author:** ![bill\_d](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bill_d/32/90623_2.png) [@bill\_d](https://discuss.elastic.co/u/bill_d)\
**Post date:** [June 24, 2021, 12:21am UTC](https://discuss.elastic.co/t/trying-to-follow-cant-follow-instructions-on-parent-child-relationships/276596/6 "2021-06-24T00:21:19Z")

</div>

Not 100% sure what is missing from the documented example, but I believe the child object needs another attribute, defined as the RoutingProperty. The new attribute needs to be set when you index the child documents - we use the parent's Id.

I'm no longer watching this, as I got my parent / child relationship working with Elasticsearch 7.10.

---

<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:** [July 22, 2021, 12:21am UTC](https://discuss.elastic.co/t/trying-to-follow-cant-follow-instructions-on-parent-child-relationships/276596/7 "2021-07-22T00:21:31Z")

</div>

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