示例#1
0
        /// <summary>
        /// Add a new mapping using the first rootObjectMapping parameter as the base to construct the new mapping.
        /// Handy if you wish to reuse a mapping.
        /// </summary>
        public CreateIndexDescriptor AddMapping <T>(RootObjectMapping rootObjectMapping, Func <PutMappingDescriptor <T>, PutMappingDescriptor <T> > typeMappingDescriptor) where T : class
        {
            typeMappingDescriptor.ThrowIfNull("typeMappingDescriptor");

            var selectorIn = new PutMappingDescriptor <T>(this._connectionSettings);
            IPutMappingRequest selectorInRequest = selectorIn;

            selectorInRequest.Mapping = rootObjectMapping;

            var d = typeMappingDescriptor(selectorIn);
            IPutMappingRequest request = d;
            var typeMapping            = request.Mapping;

            if (request.Type != null)
            {
                typeMapping.Name = request.Type.Name != null ? (PropertyNameMarker)request.Type.Name : request.Type.Type;
            }
            else
            {
                typeMapping.Name = typeof(T);
            }

            this._indexSettings.Mappings.Add(typeMapping);

            return(this);
        }
示例#2
0
        private void TestElasticsearchProjectMapping(RootObjectMapping typeMapping)
        {
            Assert.NotNull(typeMapping);
            Assert.AreEqual("string", typeMapping.Properties["content"].Type.Name);
            Assert.AreEqual("string", typeMapping.Properties["country"].Type.Name);
            Assert.AreEqual("double", typeMapping.Properties["doubleValue"].Type.Name);
            Assert.AreEqual("long", typeMapping.Properties["longValue"].Type.Name);
            Assert.AreEqual("boolean", typeMapping.Properties["boolValue"].Type.Name);
            Assert.AreEqual("integer", typeMapping.Properties["intValues"].Type.Name);
            Assert.AreEqual("float", typeMapping.Properties["floatValues"].Type.Name);
            Assert.AreEqual("string", typeMapping.Properties["name"].Type.Name);
            Assert.AreEqual("date", typeMapping.Properties["startedOn"].Type.Name);
            Assert.AreEqual("long", typeMapping.Properties["stupidIntIWantAsLong"].Type.Name);
            Assert.AreEqual("float", typeMapping.Properties["floatValue"].Type.Name);
            Assert.AreEqual("integer", typeMapping.Properties["id"].Type.Name);
            Assert.AreEqual("integer", typeMapping.Properties["loc"].Type.Name);
            Assert.AreEqual("geo_point", typeMapping.Properties["origin"].Type.Name);
            Assert.AreEqual("object", typeMapping.Properties["product"].Type.Name);

            var productMapping = typeMapping.Properties["product"] as ObjectMapping;

            Assert.NotNull(productMapping);
            Assert.AreEqual("string", productMapping.Properties["name"].Type.Name);
            Assert.AreEqual("string", productMapping.Properties["id"].Type.Name);

            var countryMapping = typeMapping.Properties["country"] as StringMapping;

            Assert.NotNull(countryMapping);
            Assert.AreEqual(FieldIndexOption.NotAnalyzed, countryMapping.Index);
        }
示例#3
0
        /// <inheritdoc cref="ISearchStore{TDocument}.CreateDocumentType" />
        public void CreateDocumentType()
        {
            if (_log.IsInfoEnabled)
            {
                _log.Info("Create Document type : " + _documentTypeName);
            }

            var client = GetClient();

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

            foreach (var field in _definition.Fields)
            {
                IElasticType elasticType = _factory.GetElasticType(field);
                if (elasticType != null)
                {
                    indexDefinition.Properties.Add(field.FieldName, elasticType);
                }
            }

            var res = client.Map <TDocument>(x => x.InitializeUsing(indexDefinition));

            res.CheckStatus("Map");
        }
示例#4
0
		private void TestMapping(RootObjectMapping typeMapping)
		{
			Assert.NotNull(typeMapping);
			Assert.AreEqual("string", typeMapping.Properties["content"].Type.Name);
			Assert.AreEqual("string", typeMapping.Properties["country"].Type.Name);
			Assert.AreEqual("double", typeMapping.Properties["doubleValue"].Type.Name);
			Assert.AreEqual("long", typeMapping.Properties["longValue"].Type.Name);
			Assert.AreEqual("boolean", typeMapping.Properties["boolValue"].Type.Name);
			Assert.AreEqual("integer", typeMapping.Properties["intValues"].Type.Name);
			Assert.AreEqual("float", typeMapping.Properties["floatValues"].Type.Name);
			Assert.AreEqual("string", typeMapping.Properties["name"].Type.Name);
			Assert.AreEqual("date", typeMapping.Properties["startedOn"].Type.Name);
			Assert.AreEqual("long", typeMapping.Properties["stupidIntIWantAsLong"].Type.Name);
			Assert.AreEqual("float", typeMapping.Properties["floatValue"].Type.Name);
			Assert.AreEqual("integer", typeMapping.Properties["id"].Type.Name);
			Assert.AreEqual("integer", typeMapping.Properties["loc"].Type.Name);
			Assert.AreEqual("geo_point", typeMapping.Properties["origin"].Type.Name);
			Assert.AreEqual("object", typeMapping.Properties["product"].Type.Name);

			var productMapping = typeMapping.Properties["product"] as ObjectMapping;
			Assert.NotNull(productMapping);
			Assert.AreEqual("string", productMapping.Properties["name"].Type.Name);
			Assert.AreEqual("string", productMapping.Properties["id"].Type.Name);

			var countryMapping = typeMapping.Properties["country"] as StringMapping;
			Assert.NotNull(countryMapping);
			Assert.AreEqual(FieldIndexOption.NotAnalyzed, countryMapping.Index);

            var tupleMapping = typeMapping.Properties["genericTuple"] as ObjectMapping;
            Assert.NotNull(tupleMapping);
            Assert.AreEqual("integer", tupleMapping.Properties["item1"].Type.Name);
            Assert.AreEqual("integer", tupleMapping.Properties["item2"].Type.Name);
		}
		private void TestPersonMapping(RootObjectMapping typeMapping)
		{
			Assert.NotNull(typeMapping);
			Assert.AreEqual("string", typeMapping.Properties["email"].Type.Name);
			var firstNameMapping = typeMapping.Properties["email"] as StringMapping;
			firstNameMapping.Should().NotBeNull();
			firstNameMapping.Index.Should().Be(FieldIndexOption.NotAnalyzed);
		}
 public void Accept(RootObjectMapping mapping)
 {
     if (mapping == null)
     {
         return;
     }
     this._visitor.Visit(mapping);
     this.Accept(mapping.Properties);
 }
示例#7
0
        private void TestPersonMapping(RootObjectMapping typeMapping)
        {
            Assert.NotNull(typeMapping);
            Assert.AreEqual("string", typeMapping.Properties["email"].Type.Name);
            var firstNameMapping = typeMapping.Properties["email"] as StringMapping;

            firstNameMapping.Should().NotBeNull();
            firstNameMapping.Index.Should().Be(FieldIndexOption.NotAnalyzed);
        }
示例#8
0
        public PutMappingDescriptor <T> InitializeUsing(RootObjectMapping rootObjectMapping)
        {
            if (rootObjectMapping == null)
            {
                return(this);
            }

            Self.Mapping = rootObjectMapping;
            return(this);
        }
示例#9
0
        public void CanDeserializeEmptyRootMapping()
        {
            var rootMapping = new RootObjectMapping()
            {
            };
            var json = TestElasticClient.Serialize(rootMapping);

            var mapping = TestElasticClient.Deserialize <RootObjectMapping>(json);

            TestElasticClient.Serialize(mapping).JsonEquals(json);
        }
        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);
        }
示例#11
0
        public void CreateIndexMultiFieldMap()
        {
            var client = this.Client;

            var typeMapping = new RootObjectMapping();

            typeMapping.Name = Guid.NewGuid().ToString("n");
            var property = new MultiFieldMapping();

            var primaryField = new StringMapping()
            {
                Index = FieldIndexOption.NotAnalyzed
            };

            var analyzedField = new StringMapping()
            {
                Index = FieldIndexOption.Analyzed
            };

            property.Fields.Add("name", primaryField);
            property.Fields.Add("name_analyzed", analyzedField);
            typeMapping.Properties = typeMapping.Properties ?? new Dictionary <PropertyNameMarker, IElasticType>();
            typeMapping.Properties.Add("name", property);

            var settings = new IndexSettings();

            settings.Mappings.Add(typeMapping);
            settings.NumberOfReplicas = 1;
            settings.NumberOfShards   = 5;
            settings.Analysis.Analyzers.Add("snowball", new SnowballAnalyzer {
                Language = "English"
            });

            var indexName = Guid.NewGuid().ToString();
            var response  = client.CreateIndex(indexName, i => i.InitializeUsing(settings));

            Assert.IsTrue(response.IsValid);
            Assert.IsTrue(response.Acknowledged);

            var inferrer = new ElasticInferrer(this.Settings);
            var typeName = inferrer.PropertyName(typeMapping.Name);

            Assert.IsNotNull(this.Client.GetMapping <ElasticsearchProject>(gm => gm.Index(indexName).Type(typeName)));

            var deleteResponse = client.DeleteIndex(i => i.Index(indexName));

            Assert.IsTrue(deleteResponse.IsValid);
            Assert.IsTrue(deleteResponse.Acknowledged);
        }
示例#12
0
        public void CreateIndexMultiFieldMap()
        {
            var client = this._client;

            var typeMapping = new RootObjectMapping();

            typeMapping.TypeNameMarker = Guid.NewGuid().ToString("n");
            var property = new MultiFieldMapping();

            var primaryField = new StringMapping()
            {
                Index = FieldIndexOption.not_analyzed
            };

            var analyzedField = new StringMapping()
            {
                Index = FieldIndexOption.analyzed
            };

            property.Fields.Add("name", primaryField);
            property.Fields.Add("name_analyzed", analyzedField);
            typeMapping.Properties = typeMapping.Properties ?? new Dictionary <string, IElasticType>();
            typeMapping.Properties.Add("name", property);

            var settings = new IndexSettings();

            settings.Mappings.Add(typeMapping);
            settings.NumberOfReplicas = 1;
            settings.NumberOfShards   = 5;
            settings.Analysis.Analyzers.Add("snowball", new SnowballAnalyzer {
                Language = "English"
            });

            var indexName = Guid.NewGuid().ToString();
            var response  = client.CreateIndex(indexName, settings);

            Assert.IsTrue(response.IsValid);
            Assert.IsTrue(response.OK);

            var typeName = typeMapping.TypeNameMarker.Resolve(this._settings);

            Assert.IsNotNull(this._client.GetMapping(indexName, typeName));

            var deleteResponse = client.DeleteIndex(indexName);

            Assert.IsTrue(deleteResponse.IsValid);
            Assert.IsTrue(deleteResponse.OK);
        }
示例#13
0
        protected void SetTtl(String type, String defaultDuration)
        {
            if (!Client.IndexExists(x => x.Index(EsIndex)).Exists)
            {
                _log.Info("Create ES index: " + EsIndex);
                var response = Client.CreateIndex(EsIndex, id => id.NumberOfShards(2));
            }
            var indexDefinition = new RootObjectMapping
            {
                Properties = new Dictionary <PropertyNameMarker, IElasticType>(),
                Name       = "log",
            };

            var ttlDescriptor = new TtlFieldMappingDescriptor();

            ttlDescriptor.Enable(true);
            ttlDescriptor.Default(defaultDuration);
            indexDefinition.TtlFieldMappingDescriptor = ttlDescriptor;

            var notAnalyzedProperty = new StringMapping
            {
                Index = FieldIndexOption.NotAnalyzed
            };

            //property.Fields.Add("le", property);
            indexDefinition.Properties.Add("le", notAnalyzedProperty);
            indexDefinition.Properties.Add("us", notAnalyzedProperty);
            indexDefinition.Properties.Add("lo", notAnalyzedProperty);
            indexDefinition.Properties.Add("do", notAnalyzedProperty);
            indexDefinition.Properties.Add("ma", notAnalyzedProperty);
            indexDefinition.Properties.Add("pn", notAnalyzedProperty);
            indexDefinition.Properties.Add("ln", notAnalyzedProperty);
            indexDefinition.Properties.Add("cn", notAnalyzedProperty);
            indexDefinition.Properties.Add("ts", new DateMapping());

            indexDefinition.Properties.Add("mongo-server", notAnalyzedProperty);
            indexDefinition.Properties.Add("collection", notAnalyzedProperty);
            indexDefinition.Properties.Add("source", notAnalyzedProperty);
            Client.Map <object>(x => x
                                .InitializeUsing(indexDefinition)
                                .Index(EsIndex)
                                .Type("log")
                                );
            _log.Info("ES Mapping set");
        }
        public void CreateIndexMultiFieldMap()
        {
            var client = this._client;

            var typeMapping = new RootObjectMapping();
            typeMapping.Name = Guid.NewGuid().ToString("n");
            var property = new MultiFieldMapping();

            var primaryField = new StringMapping()
            {
                Index = FieldIndexOption.not_analyzed
            };

            var analyzedField = new StringMapping()
            {
                Index = FieldIndexOption.analyzed
            };

            property.Fields.Add("name", primaryField);
            property.Fields.Add("name_analyzed", analyzedField);
            typeMapping.Properties = typeMapping.Properties ?? new Dictionary<PropertyNameMarker, IElasticType>();
            typeMapping.Properties.Add("name", property);

            var settings = new IndexSettings();
            settings.Mappings.Add(typeMapping);
            settings.NumberOfReplicas = 1;
            settings.NumberOfShards = 5;
            settings.Analysis.Analyzers.Add("snowball", new SnowballAnalyzer { Language = "English" });

            var indexName = Guid.NewGuid().ToString();
            var response = client.CreateIndex(indexName, i=>i.InitializeUsing(settings));

            Assert.IsTrue(response.IsValid);
            Assert.IsTrue(response.Acknowledged);

            var inferrer = new ElasticInferrer(this._settings);
            var typeName = inferrer.PropertyName(typeMapping.Name);
            Assert.IsNotNull(this._client.GetMapping(gm=>gm.Index(indexName).Type(typeName)));

            var deleteResponse = client.DeleteIndex(i=>i.Index(indexName));

            Assert.IsTrue(deleteResponse.IsValid);
            Assert.IsTrue(deleteResponse.Acknowledged);
        }
示例#15
0
        public void CreateIndexMultiFieldMap()
        {
            var client = this._client;

            var typeMapping = new RootObjectMapping();
            typeMapping.Name = Guid.NewGuid().ToString("n");
            var property = new MultiFieldMapping();

            var primaryField = new StringMapping()
            {
                Index = FieldIndexOption.not_analyzed
            };

            var analyzedField = new StringMapping()
            {
                Index = FieldIndexOption.analyzed
            };

            property.Fields.Add("name", primaryField);
            property.Fields.Add("name_analyzed", analyzedField);
            typeMapping.Properties = typeMapping.Properties ?? new Dictionary<string, IElasticType>();
            typeMapping.Properties.Add("name", property);

            var settings = new IndexSettings();
            settings.Mappings.Add(typeMapping);
            settings.NumberOfReplicas = 1;
            settings.NumberOfShards = 5;
            settings.Analysis.Analyzer.Add("snowball", new SnowballAnalyzerSettings { Language = "English" });

            var indexName = Guid.NewGuid().ToString();
            var response = client.CreateIndex(indexName, settings);

            Assert.IsTrue(response.IsValid);
            Assert.IsTrue(response.OK);

            Assert.IsNotNull(this._client.GetMapping(indexName, typeMapping.Name));

            response = client.DeleteIndex(indexName);

            Assert.IsTrue(response.IsValid);
            Assert.IsTrue(response.OK);
        }
示例#16
0
文件: MapTests.cs 项目: bizl/NEST
        private void TestMapping(RootObjectMapping typeMapping)
        {
            Assert.NotNull(typeMapping);
            Assert.AreEqual("string", typeMapping.Properties["content"].Type.Name);
            Assert.AreEqual("string", typeMapping.Properties["country"].Type.Name);
            Assert.AreEqual("double", typeMapping.Properties["doubleValue"].Type.Name);
            Assert.AreEqual("long", typeMapping.Properties["longValue"].Type.Name);
            Assert.AreEqual("boolean", typeMapping.Properties["boolValue"].Type.Name);
            Assert.AreEqual("integer", typeMapping.Properties["intValues"].Type.Name);
            Assert.AreEqual("float", typeMapping.Properties["floatValues"].Type.Name);
            Assert.AreEqual("string", typeMapping.Properties["name"].Type.Name);
            Assert.AreEqual("date", typeMapping.Properties["startedOn"].Type.Name);
            Assert.AreEqual("long", typeMapping.Properties["stupidIntIWantAsLong"].Type.Name);
            Assert.AreEqual("float", typeMapping.Properties["floatValue"].Type.Name);
            Assert.AreEqual("integer", typeMapping.Properties["id"].Type.Name);
            Assert.AreEqual("integer", typeMapping.Properties["loc"].Type.Name);
            var mapping = typeMapping.Properties["country"] as StringMapping;

            Assert.NotNull(mapping);
            Assert.AreEqual(FieldIndexOption.not_analyzed, mapping.Index);
            //Assert.AreEqual("elasticsearchprojects", typeMapping.Parent.Type);

            Assert.AreEqual("geo_point", typeMapping.Properties["origin"].Type.Name);

            //Assert.IsTrue(typeMapping.Properties["origin"].Dynamic);
            //Assert.AreEqual("double", typeMapping.Properties["origin"].Properties["lat"].Type);
            //Assert.AreEqual("double", typeMapping.Properties["origin"].Properties["lon"].Type);

            //Assert.IsTrue(typeMapping.Properties["followers"].Dynamic);
            //Assert.AreEqual("long", typeMapping.Properties["followers"].Properties["age"].Type);
            //Assert.AreEqual("date", typeMapping.Properties["followers"].Properties["dateOfBirth"].Type);
            //Assert.AreEqual("string", typeMapping.Properties["followers"].Properties["email"].Type);
            //Assert.AreEqual("string", typeMapping.Properties["followers"].Properties["firstName"].Type);
            //Assert.AreEqual("long", typeMapping.Properties["followers"].Properties["id"].Type);
            //Assert.AreEqual("string", typeMapping.Properties["followers"].Properties["lastName"].Type);

            //Assert.IsTrue(typeMapping.Properties["followers"].Properties["placeOfBirth"].Dynamic);
            //Assert.AreEqual("double", typeMapping.Properties["followers"].Properties["placeOfBirth"].Properties["lat"].Type);
            //Assert.AreEqual("double", typeMapping.Properties["followers"].Properties["placeOfBirth"].Properties["lon"].Type);
        }
示例#17
0
文件: MapTests.cs 项目: Moran007/NEST
        private void TestMapping(RootObjectMapping typeMapping)
        {
            Assert.NotNull(typeMapping);
            Assert.AreEqual("string", typeMapping.Properties["content"].Type);
            Assert.AreEqual("string", typeMapping.Properties["country"].Type);
            Assert.AreEqual("double", typeMapping.Properties["doubleValue"].Type);
            Assert.AreEqual("long", typeMapping.Properties["longValue"].Type);
            Assert.AreEqual("boolean", typeMapping.Properties["boolValue"].Type);
            Assert.AreEqual("integer", typeMapping.Properties["intValues"].Type);
            Assert.AreEqual("float", typeMapping.Properties["floatValues"].Type);
            Assert.AreEqual("multi_field", typeMapping.Properties["name"].Type);
            Assert.AreEqual("date", typeMapping.Properties["startedOn"].Type);
            Assert.AreEqual("long", typeMapping.Properties["stupidIntIWantAsLong"].Type);
            Assert.AreEqual("float", typeMapping.Properties["floatValue"].Type);
            Assert.AreEqual("integer", typeMapping.Properties["id"].Type);
            Assert.AreEqual("multi_field", typeMapping.Properties["loc"].Type);
            var mapping = typeMapping.Properties["country"] as StringMapping;
            Assert.NotNull(mapping);
            Assert.AreEqual(FieldIndexOption.not_analyzed, mapping.Index);
            //Assert.AreEqual("elasticsearchprojects", typeMapping.Parent.Type);

            Assert.AreEqual("geo_point", typeMapping.Properties["origin"].Type);

            //Assert.IsTrue(typeMapping.Properties["origin"].Dynamic);
            //Assert.AreEqual("double", typeMapping.Properties["origin"].Properties["lat"].Type);
            //Assert.AreEqual("double", typeMapping.Properties["origin"].Properties["lon"].Type);

            //Assert.IsTrue(typeMapping.Properties["followers"].Dynamic);
            //Assert.AreEqual("long", typeMapping.Properties["followers"].Properties["age"].Type);
            //Assert.AreEqual("date", typeMapping.Properties["followers"].Properties["dateOfBirth"].Type);
            //Assert.AreEqual("string", typeMapping.Properties["followers"].Properties["email"].Type);
            //Assert.AreEqual("string", typeMapping.Properties["followers"].Properties["firstName"].Type);
            //Assert.AreEqual("long", typeMapping.Properties["followers"].Properties["id"].Type);
            //Assert.AreEqual("string", typeMapping.Properties["followers"].Properties["lastName"].Type);

            //Assert.IsTrue(typeMapping.Properties["followers"].Properties["placeOfBirth"].Dynamic);
            //Assert.AreEqual("double", typeMapping.Properties["followers"].Properties["placeOfBirth"].Properties["lat"].Type);
            //Assert.AreEqual("double", typeMapping.Properties["followers"].Properties["placeOfBirth"].Properties["lon"].Type);
        }
		public void Accept(RootObjectMapping mapping)
		{
			if (mapping == null) return;
			this._visitor.Visit(mapping);
			this.Accept(mapping.Properties);
		}
示例#19
0
        public BulkOperationsResponse Ingest(IOpenSearchableElasticType type, IOpenSearchResultCollection results)
        {
            OpenSearchFactory.RemoveLinksByRel(ref results, "self");
            OpenSearchFactory.RemoveLinksByRel(ref results, "search");

            IElasticCollection docs = type.FromOpenSearchResultCollection(results);

            BulkRequest bulkRequest = new BulkRequest()
            {
                Refresh     = true,
                Consistency = Consistency.One,
                Index       = type.Index,
                Type        = type.Type,
                Operations  = new List <IBulkOperation>()
            };

            RootObjectMapping currentMapping = null;

            try {
                var mappingResponse = client.GetMapping <IElasticType>(g => g.Index(type.Index.Name).Type(type.Type.Name));
                currentMapping = mappingResponse.Mapping;
            } catch (Exception) {
            }

            var rootObjectMapping = type.GetRootMapping();

            if (!rootObjectMapping.Equals(currentMapping))
            {
                client.Map <IElasticType>(m => m.Index(type.Index.Name).Type(type.Type.Name));
            }

            foreach (var doc in docs.ElasticItems)
            {
                var bulkIndexOperation = new BulkIndexOperation <IElasticItem>(doc);
                bulkIndexOperation.Id   = ((IOpenSearchResultItem)doc).Identifier;
                bulkIndexOperation.Type = type.Type.Name;
                var bulkOp = bulkIndexOperation;
                bulkRequest.Operations.Add(bulkOp);
            }

            var response = client.Bulk(bulkRequest);

            BulkOperationsResponse ingestionResponse = new BulkOperationsResponse();

            foreach (var item in response.Items)
            {
                if (!item.IsValid)
                {
                    ingestionResponse.Errors++;
                    continue;
                }
                if (item.Version == "1")
                {
                    ingestionResponse.Added++;
                }
                else
                {
                    ingestionResponse.Updated++;
                }
            }

            return(ingestionResponse);
        }
示例#20
0
        public void CanDeserializeRootMapping()
        {
            var rootMapping = new RootObjectMapping()
            {
                AllFieldMapping = new AllFieldMapping()
                {
                    Enabled       = true,
                    IndexAnalyzer = "index_analyzer"
                },
                SourceFieldMappingDescriptor = new SourceFieldMapping()
                {
                    Compress = false,
                    Excludes = new[] { "excluded" }
                },
                RoutingFieldMapping = new RoutingFieldMapping()
                {
                    Path = "routing_path"
                },
                SizeFieldMapping = new SizeFieldMapping()
                {
                    Enabled = true,
                },
                TtlFieldMappingDescriptor = new TtlFieldMapping()
                {
                    Enabled = true,
                },
                IdFieldMappingDescriptor = new IdFieldMapping()
                {
                    Index = "not_analyzed",
                    Store = false,
                    Path  = "id_field",
                },
                TimestampFieldMapping = new TimestampFieldMapping()
                {
                    Enabled = true,
                    Format  = "YYY-MM-dd",
                    Path    = "the_timestamp",
                },
                IndexFieldMapping = new IndexFieldMapping()
                {
                    Enabled = true,
                },
                AnalyzerFieldMapping = new AnalyzerFieldMapping()
                {
                    Path = "index_path",
                },
                BoostFieldMapping = new BoostFieldMapping()
                {
                    Name      = "boost",
                    NullValue = 2.0,
                },
                Parent = new ParentTypeMapping()
                {
                    Type = "type"
                },
                TypeFieldMappingDescriptor = new TypeFieldMapping()
                {
                    Index = NonStringIndexOption.NotAnalyzed,
                    Store = false,
                }
            };
            var json = TestElasticClient.Serialize(rootMapping);

            var mapping = TestElasticClient.Deserialize <RootObjectMapping>(json);

            TestElasticClient.Serialize(mapping).JsonEquals(json);
        }
		public void CanDeserializeRootMapping()
		{
			var rootMapping = new RootObjectMapping()
			{
				AllFieldMapping = new AllFieldMapping()
				{
					Enabled = true,
					IndexAnalyzer = "index_analyzer"
				},
				SourceFieldMappingDescriptor = new SourceFieldMapping()
				{
					Compress = false,
					Excludes = new[] { "excluded" }
				},
				RoutingFieldMapping = new RoutingFieldMapping()
				{
					Path = "routing_path"
				},
				SizeFieldMapping = new SizeFieldMapping()
				{
					Enabled = true,
				},
				TtlFieldMappingDescriptor = new TtlFieldMapping()
				{
					Enabled = true,
				},
				IdFieldMappingDescriptor = new IdFieldMapping()
				{
					Index = "not_analyzed",
					Store = false,
					Path = "id_field",
				},
				TimestampFieldMapping = new TimestampFieldMapping()
				{
					Enabled = true,
					Format = "YYY-MM-dd",
					Path = "the_timestamp",
				},
				IndexFieldMapping = new IndexFieldMapping()
				{
					Enabled = true,
				},
				AnalyzerFieldMapping = new AnalyzerFieldMapping()
				{
					Path = "index_path",
				},
				BoostFieldMapping = new BoostFieldMapping()
				{
					Name = "boost",
					NullValue = 2.0,
				},
				Parent = new ParentTypeMapping()
				{
					Type = "type"
				},
				TypeFieldMappingDescriptor = new TypeFieldMapping()
				{
					Index = NonStringIndexOption.NotAnalyzed, 
					Store = false,
				}
			};
			var json = TestElasticClient.Serialize(rootMapping);

			var mapping = TestElasticClient.Deserialize<RootObjectMapping>(json);
			TestElasticClient.Serialize(mapping).JsonEquals(json);
		}
		public void CanDeserializeEmptyRootMapping()
		{
			var rootMapping = new RootObjectMapping()
			{
			};
			var json = TestElasticClient.Serialize(rootMapping);

			var mapping = TestElasticClient.Deserialize<RootObjectMapping>(json);
			TestElasticClient.Serialize(mapping).JsonEquals(json);
		}
示例#23
0
 public void Accept(RootObjectMapping mapping)
 {
     this._visitor.Visit(mapping);
     this.Accept(mapping.Properties);
 }
 public void Visit(RootObjectMapping mapping)
 {
     this.PrettyPrint(mapping);
 }
		public void Accept(RootObjectMapping mapping)
		{
			this._visitor.Visit(mapping);
			this.Accept(mapping.Properties);
		}