我的代码可能有问题,因为相同的代码有时会将嵌套应用于我的索引,有时则不会。
为什么?
我忘记了什么吗?
.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; }
}