Пример #1
0
        public void TestTemplate()
        {
            var tempkey = "test_template_key1";

            client.DeleteTemplate(tempkey);

            var template = new TemplateSetting(tempkey);

            template.Template     = "business_*";
            template.IndexSetting = new TemplateIndexSetting(3, 2);

            var type1 = new TypeSetting("mytype")
            {
            };

            type1.AddNumField("identity", NumType.Float);
            type1.AddDateField("datetime");

            var type2 = new TypeSetting("mypersontype");

            type2.AddStringField("personid");

            type2.SourceSetting         = new SourceSetting();
            type2.SourceSetting.Enabled = false;

            template.AddTypeSetting(type1);
            template.AddTypeSetting(type2);

            var jsonstr = JsonSerializer.Get(template);

            Console.WriteLine(jsonstr);

            var result = client.CreateTemplate(tempkey, template);

            Console.WriteLine(result.JsonString);
            Assert.AreEqual(true, result.Success);

            result = client.CreateIndex("business_111");
            Assert.AreEqual(true, result.Success);
            result = client.CreateIndex("business_132");
            Assert.AreEqual(true, result.Success);
            result = client.CreateIndex("business_31003");
            Assert.AreEqual(true, result.Success);

            client.Refresh();
            var temp = client.GetTemplate(tempkey);

            TemplateSetting result1;

            Assert.AreEqual(true, temp.TryGetValue(tempkey, out result1));
            Assert.AreEqual(template.Order, result1.Order);
            Assert.AreEqual(template.Template, result1.Template);

            client.DeleteIndex("business_111");
            client.DeleteIndex("business_132");
            client.DeleteIndex("business_31003");
        }
Пример #2
0
        public void TestCreateUser()
        {
            var template_key = "test_user_template";

            client.DeleteTemplate(template_key);

            var template = new TemplateSetting(template_key);

            template.Template     = "test_user*";
            template.IndexSetting = new TemplateIndexSetting(1, 1);
            var type = new TypeSetting("Staff");

            type.AddStringField("Name");
            type.AddStringField("Email");
            type.AddStringField("EnglishName");

            type.AddNumField("UserID", NumType.Integer);
            template.AddTypeSetting(type);

            var jsonstr = JsonSerializer.Get(template);

            Console.WriteLine(jsonstr);

            var result = client.CreateTemplate(template_key, template);

            Console.WriteLine(result.JsonString);
            Assert.AreEqual(true, result.Success);

            var temp2 = client.GetTemplate(template_key);

            Assert.AreEqual("test_user*", temp2[template_key].Template);
            Assert.True(temp2[template_key].Mappings.ContainsKey("Staff"));

            Assert.AreEqual(1, temp2[template_key].IndexSetting.NumberOfReplicas);
            Assert.AreEqual(1, temp2[template_key].IndexSetting.NumberOfShards);

            result = client.DeleteTemplate(template_key);
            Assert.AreEqual(true, result.Success);
        }