Exemplo n.º 1
0
        public void Reindex()
        {
            _client.DeleteIndex(IndexType);
            _client.CreateIndex(IndexType);

            var indexDefinition = new RootObjectMapping
            {
                Properties = new Dictionary <PropertyNameMarker, IElasticType>()
            };

            var paramsProperty = new ObjectMapping
            {
                Properties = new Dictionary <PropertyNameMarker, IElasticType>()
            };

            var numberMapping = new NumberMapping();
            var boolMapping   = new BooleanMapping();
            var stringMapping = new StringMapping
            {
                Index = FieldIndexOption.NotAnalyzed
            };

            IEnumerable <object> properties = GetAllProperties();

            foreach (var property in properties)
            {
                //switch (property.DataType)
                //{
                //    case DataType.Logic:
                //        paramsProperty.Properties.Add(property.Id, boolMapping);
                //        break;
                //    case DataType.Numeric:
                //        paramsProperty.Properties.Add(property.Id, numberMapping);
                //        break;
                //    case DataType.Text:
                //        paramsProperty.Properties.Add(property.Id, stringMapping);
                //        break;
                //}
            }

            indexDefinition.Properties.Add(Property.Name <ProductIndex>(p => p.Params), paramsProperty);
            indexDefinition.Properties.Add(Property.Name <ProductIndex>(p => p.Id), stringMapping);
            indexDefinition.Properties.Add(Property.Name <ProductIndex>(p => p.CategoryId), stringMapping);

            _client.Map <ProductIndex>(x => x.InitializeUsing(indexDefinition));

            IEnumerable <Product> products = GetAllProducts();

            _client.IndexMany(products);
        }
 public void Visit(BooleanMapping mapping)
 {
     this.PrettyPrint(mapping);
 }