1

I have this example written in "NEST library 7.6.1" of definition of Parent/Child relationships between elements.

"Product" is a parent.

"Stock", "Supplier", "Category" is a child of a Product

var createIndex = _ElasticClient.Indices.Create(_IndexName, x => x
     .Settings(s => s
                     .NumberOfReplicas(0)
                     .RefreshInterval(-1)
                     .NumberOfShards(5))
    .Index<BaseDocument>()
    .Map<BaseDocument>(m => m
        .RoutingField(r => r.Required())
        .AutoMap<Product>()
        .Properties<Product>(props => props
        //You can describe your properties below for Manual mapping
        .Text(s => s
           .Name(n => n.Name)
           .Analyzer("default")
           .Fields(pprops => pprops))
      )
                            .AutoMap<Category>()
                            .AutoMap<Supplier>()
                            .AutoMap<Stock>()
                            //You can add more join types here
                            .Properties(props => props
                                        .Join(j => j
                                            .Name(p => p.JoinField)
                                                //This is so important here. You can describe a relation that product is parent and the others is join type.
                                                .Relations(r => r
                                                .Join<Product>("category", "supplier", "stock")
                                                        )
                                        )
                                    )
                            )
);

I wonder how I can do this using the newest library for .NET/C# "Elastic.Clients.Elasticsearch"

I can't find any example that uses this latest library

Rest of the code:

public abstract class BaseDocument
{
    public virtual int Id { get; set; }
    public int Parent { get; set; }

    public JoinField JoinField { get; set; }

    public BaseDocument()
    {

    }
}
[ElasticsearchType(RelationName = "product")]
public class Product : BaseDocument
{
    [Keyword]
    public string Name { get; set; }

    public decimal Price { get; set; }
  
}
[ElasticsearchType(RelationName = "stock")]
public class Stock : BaseDocument
{
    [Keyword]
    public string Country { get; set; }

    public int Quantity { get; set; }
  
}
[ElasticsearchType(RelationName = "supplier")]
public class Supplier : BaseDocument
{
    [Keyword]
    public string SupplierDescription { get; set; }
  
}
[ElasticsearchType(RelationName = "category")]
public class Category : BaseDocument
{
    [Keyword]
    public string CategoryDescription { get; set; }
  
}```

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.