Пример #1
0
        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);
        }
Пример #2
0
        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));
        }