コード例 #1
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);
        }
コード例 #2
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");
		}
コード例 #3
0
		public OperateResult CreateTemplate(string templateName, TemplateSetting template)
		{
			Contract.Assert(template != null);

			string url = "/_template/{0}".Fill(templateName);

			string json = JsonSerializer.Get(template);
			RestResponse result = _provider.Post(url, json);

			return GetOperationResult(result);
		}
コード例 #4
0
        public void TestCreateAnalysisMapping()
        {
            var template = new TemplateSetting("index_1*");
            var type = new TypeSetting("type88");
            type.AddStringField("name", null, Store.no, IndexType.analyzed, TermVector.no, 1, null, true, true, "keyword", "keyword", "keyword");
            template.AddTypeSetting(type);
            var result = client.CreateTemplate("template_123", template).Success;
            Assert.AreEqual(true, result);
            result = client.CreateIndex("index_1123").Success;
            Assert.AreEqual(true, result);
            var a = client.Index("index_1123", "type88", "key1", "{name:\"张三\"}");
            Assert.AreEqual(true, a.Success);
            a = client.Index("index_1123", "type88", "key2", "{name:\"张三丰\"}");
            Assert.AreEqual(true, a.Success);
            a = client.Index("index_1123", "type88", "key3", "{name:\"大张旗鼓\"}");
            Assert.AreEqual(true, a.Success);
            a = client.Index("index_1123", "type88", "key4", "{name:\"子张怡\"}");
            Assert.AreEqual(true, a.Success);
            Thread.Sleep(2000);
            var count = client.Count("index_1123", "type88", "name:张");
            Assert.AreEqual(0, count);
            count = client.Count("index_1123", "type88", "name:张三");
            Assert.AreEqual(1, count);
            count = client.Count("index_1123", "type88", "name:张三丰");
            Assert.AreEqual(1, count);
            count = client.Count("index_1123", "type88", "name:张三*");
            Assert.AreEqual(2, count);
            count = client.Count("index_1123", "type88", "name:张三*");
            Assert.AreEqual(2, count);
            count = client.Count("index_1123", "type88", "name:张三?");
            Assert.AreEqual(1, count);
            count = client.Count("index_1123", "type88", "name:*张*");
            Assert.AreEqual(4, count);
            count = client.Count("index_1123", "type88", "name:?张*");
            Assert.AreEqual(2, count);

            //test for _all
            //only works after setting default_analysis to keyword(or set against filed: _all )
//			count = client.Count("index_1123", "type88", "_all:张");
//			Assert.AreEqual(0, count);
//			count = client.Count("index_1123", "type88", "_all:张三");
//			Assert.AreEqual(1, count);
//			count = client.Count("index_1123", "type88", "_all:张三丰");
//			Assert.AreEqual(1, count);
//			count = client.Count("index_1123", "type88", "_all:张三*");
//			Assert.AreEqual(2, count);
//			count = client.Count("index_1123", "type88", "_all:张三*");
//			Assert.AreEqual(2, count);
//			count = client.Count("index_1123", "type88", "_all:张三?");
//			Assert.AreEqual(1, count);
//			count = client.Count("index_1123", "type88", "_all:*张*");
//			Assert.AreEqual(4, count);
//			count = client.Count("index_1123", "type88", "_all:?张*");
//			Assert.AreEqual(2, count);
        }