Пример #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
 private void TestMapping(TypeMapping 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("string", typeMapping.Properties["name"].Type);
     Assert.AreEqual("date", typeMapping.Properties["startedOn"].Type);
     Assert.AreEqual("long", typeMapping.Properties["stupidIntIWantAsLong"].Type);
 }