Elasticsearch NEST - Filtering on multilevel nested types

后端 未结 1 1514
星月不相逢
星月不相逢 2021-02-09 11:15

I have a document model like this:

\"customer\": {  
    \"properties\": {  
        \"id\": { \"type\": \"integer\" },
        \"name\": { \"type\": \"string\         


        
相关标签:
1条回答
  • 2021-02-09 11:45

    Assuming we are modelling the customer to something on these lines

    class customer
        {
            public int id { get; set; }
            public string name { get; set;}
    
            public class Orders {
                public int id { get; set;}
                public string orderData { get; set;}
                public class OrderLines
                {
                    public int seqno { get; set; }
                    public int quantity { get; set; }
                    public int articleId { get; set; }
                }
                [ElasticProperty(Type = FieldType.Nested)]
                public List<OrderLines> orderLines { get; set; }
            }
             [ElasticProperty(Type = FieldType.Nested)]
            public List<Orders> orders { get; set; }
    
        };
    

    The query in the above case would be :

     var response = client.Search<customer>(
                    s => s.Index(<index_name_here>).Type("customer")
                    .Query(q => q.Term(p=>p.id, 1) 
                    &&
                    q.Nested(n =>
                        n.Path("orders")
                        .Query(q2=> q2.Nested(
                            n2 => n2.Path("orders.orderLines")
                            .Query(q3 => 
                                q3.Term(c=>c.orders.First().orderLines.First().articleId, <article_id_here>)))))
                   ));
    

    As far as documentation the best I have come across is the same as the one you posted in the question and the resources linked there.

    0 讨论(0)
提交回复
热议问题