Parent/Child relationships

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

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

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:

any idea? Thanks.

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