private static void CreateEmployeeIndex() { var settings = new IndexSettings(); var typeMapping = new TypeMapping("employee"); var stringNotAnalyzed = new TypeMappingProperty { Type = "string", Index = "not_analyzed" }; //ElasticSearch camel-cases field names typeMapping.Properties = new Dictionary <string, TypeMappingProperty>(); typeMapping.Properties.Add("id", stringNotAnalyzed); typeMapping.Properties.Add("companyId", stringNotAnalyzed); settings.Mappings.Add(typeMapping); settings.NumberOfReplicas = 1; settings.NumberOfShards = 5; //default analyzer is Standard var result = esClient.CreateIndex("employees", settings); if (!result.OK) { Log("Unable to create and configure employees ElasticSearch index"); return; } Log("Employees index created"); }
public void CreateIndexMultiFieldMap() { var client = this.ConnectedClient; var typeMapping = new TypeMapping(Guid.NewGuid().ToString("n")); var property = new TypeMappingProperty { Type = "multi_field" }; var primaryField = new TypeMappingProperty { Type = "string", Index = "not_analyzed" }; var analyzedField = new TypeMappingProperty { Type = "string", Index = "analyzed" }; property.Fields = new Dictionary <string, TypeMappingProperty>(); property.Fields.Add("name", primaryField); property.Fields.Add("name_analyzed", analyzedField); 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.ConnectedClient.GetMapping(indexName, typeMapping.Name)); response = client.DeleteIndex(indexName); Assert.IsTrue(response.IsValid); Assert.IsTrue(response.OK); }
public void CreateIndexMultiFieldMap() { var client = this.ConnectedClient; var typeMapping = new TypeMapping(Guid.NewGuid().ToString("n")); var property = new TypeMappingProperty { Type = "multi_field" }; var primaryField = new TypeMappingProperty { Type = "string", Index = "not_analyzed" }; var analyzedField = new TypeMappingProperty { Type = "string", Index = "analyzed" }; property.Fields = new Dictionary<string, TypeMappingProperty>(); property.Fields.Add("name", primaryField); property.Fields.Add("name_analyzed", analyzedField); 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.ConnectedClient.GetMapping(indexName, typeMapping.Name)); response = client.DeleteIndex(indexName); Assert.IsTrue(response.IsValid); Assert.IsTrue(response.OK); }
public void PutMapping() { var fieldName = Guid.NewGuid().ToString(); var mapping = this.ConnectedClient.GetMapping <ElasticSearchProject>(); var property = new TypeMappingProperty { Type = "string", Index = "not_analyzed" }; mapping.Properties.Add(fieldName, property); var response = this.ConnectedClient.Map(mapping); Assert.IsTrue(response.IsValid); Assert.IsTrue(response.OK); mapping = this.ConnectedClient.GetMapping <ElasticSearchProject>(); Assert.IsNotNull(mapping.Properties.ContainsKey(fieldName)); }
public void PutMapping() { var fieldName = Guid.NewGuid().ToString(); var mapping = this.ConnectedClient.GetMapping<ElasticSearchProject>(); var property = new TypeMappingProperty { Type = "string", Index = "not_analyzed" }; mapping.Properties.Add(fieldName, property); var response = this.ConnectedClient.Map(mapping); Assert.IsTrue(response.IsValid); Assert.IsTrue(response.OK); mapping = this.ConnectedClient.GetMapping<ElasticSearchProject>(); Assert.IsNotNull(mapping.Properties.ContainsKey(fieldName)); }