Adding the Parent Child Relationship to nested object

public class Parent
{
    public string Field1 { get; set; }
    public string Field2 { get; set; }
    public List<DemoClass> Field3 { get; set; }

}

public class DemoClass
{
    public int Id { get; set; }
}

public class ChildClass
{
    public string Field1 { get; set; }
    public string Field2 { get; set; }
}

So child document will be mapped to the Id of the demo class and this class itself is under class parent. This is the problem statement

How create the parent child relation in above scenario.

Hi,

You should read this doc: https://www.elastic.co/guide/en/elasticsearch/reference/7.1/nested.html

Hello xavierfacq

My problem is related to the parent child not with nested item.

It would be helpful if you provided some additional context and information about your data. Whether to use parent-child relations or not often depend on the cardinality between entities, update and creation patterns as well as how you need to query the data. It often makes sense to simplify the model by denormalizing the data rather than try to use parent-child to replicate some relational model.

Hello Christian

There is actually a frequent update to the child document that's why I am going for the Parent and Child relationship. And I want to map the field of the list object to child.
And also Is there any way I can search from both parent and child index at same time.

Parent-child relationships are typically used when the parent document is frequently updated and this would result in a large number of updates if the model was flattened and denormalized. If the children are the ones updated more frequently a flattened model might work better. It would however help if you provided some details around the use case and the data.

Parent-child relations requires all parents and related children to be located in the same shard/index.

1 Like

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