NEST Elasticsearch C# - 问题MAPPING NESTED索引多个bahaviours

时间:2018-05-11 07:04:03

标签: c# elasticsearch nested nest elastic-stack

我的代码可能有问题,因为相同的代码有时会将嵌套应用于我的索引,有时则不会。

为什么?

我忘记了什么吗?

.Mappings会覆盖注释吗?注释与.Mappings之间是否存在任何映射冲突?

client = new ElasticClient(settings);

if (client.IndexExists(defaultIndexName).Exists)
            client.DeleteIndex(defaultIndexName);

client.CreateIndex(defaultIndexName, c => c
                             .Mappings(ms => ms
                                     .Map<Store>(m => m
                                         .AutoMap()                                 
                                         .Properties(p => p
                                             .Nested<Product>(n => n
                                                 .Name(nn => nn.Products)
                                                 .AutoMap()
                                                 .Properties(pps => pps
                                                   .Keyword(k => k
                                                        .Name(l => l.Label)

                                ))
                            )
                        )
                    )
                )
            );

POCOS

 public class Store
 {       
        public int Id { get; set; }
        [Keyword]
        public string Name{ get; set; }
        [Nested]
        public List<Product> Products{ get; set; }
    }

产品

 public class Product
    {   
        public int Id { get; set; }
        public double Price { get; set; }
        [Keyword]
        public string Label { get; set; }           
        public double Quantity { get; set; }
        public double Total { get; set; }
        public int StoreId { get; set; }
    } 

0 个答案:

没有答案