使用NEST在Elasticsearch中创建类型

时间:2018-01-22 11:59:43

标签: c# elasticsearch nest

所以我构建了一个非常基本的弹性示例,仅使用一个Type(产品)我能够使用automap来构建这个并且一切运行良好,现在我想扩展这个并添加更多类型我遇到问题但是没有任何真正的异常被抛出来给我一个关于出了什么问题的线索。

class Product
    {

        public int ProductId { get; set; }
        public string Name { get; set; }
        public string ProductCode { get; set; }
        public string Barcode { get; set; }
        public Nullable<int> ProductCategoryId { get; set; }
        public int Length { get; set; }
        public int Height { get; set; }
        public int ProductTypeId { get; set; }
        public string Url { get; set; }
        public Nullable<int> ProductBrandId { get; set; }
        public int Width { get; set; }
        public string Html { get; set; }
        public string Description { get; set; }
        public string MetaTitle { get; set; }
        public string MetaKeywords { get; set; }
        public string MetaDescription { get; set; }
        public decimal CostPrice { get; set; }
        public Nullable<int> ProductBuyingPriceId { get; set; }
        public int DispatchTimeInDays { get; set; }
        public int LeadTimeInDays { get; set; }
        public string ManufacturerPartNumber { get; set; }
        public string Notes { get; set; }
        public int StockAvailable { get; set; }
        public decimal WeightKg { get; set; }
        public Nullable<int> SellingPriceGroupId { get; set; }
        public Nullable<decimal> ReviewRating { get; set; }
        public int ReviewRatingCount { get; set; }
        public bool NonReturnable { get; set; }
        public bool LimitedStock { get; set; }
        public Nullable<int> TaxRateId { get; set; }

        public virtual ProductCategory ProductCategory { get; set; }

    }

    class ProductCategory
    {
        public int ProductCategoryId { get; set; }
        public string Name { get; set; }
        public Nullable<int> ParentProductCategoryId { get; set; }
        public string FullPath { get; set; }
        public string Code { get; set; }
    }

        private void button1_Click(object sender, EventArgs e)
        {

            var des = new CreateIndexDescriptor("myindex")
                .Mappings(ms => ms
                .Map<Product>(m => m.AutoMap())
                .Map<ProductCategory>(m => m.AutoMap())
                );

            var res = elasticClient.CreateIndex(des);
            Output.AppendText(res.ToString());
            Output.AppendText(Environment.NewLine);
            Output.AppendText("Index Created");
            Output.AppendText(Environment.NewLine);


        }

如上所述,如果我只是包含它,如果我添加产品类别没有任何反应。 TIA

1 个答案:

答案 0 :(得分:0)

感谢您的回复正如Russ所说我试图拥有多种不会起作用的类型