Count() 공개 메소드

public Count ( string queryString ) : int
queryString string
리턴 int
		public void TestBulk()
		{
			var client = new ElasticSearchClient("localhost");
			var fields = new Dictionary<string, object>();
			fields.Add("name", "jack");
			fields.Add("age", 25);
			
			var index = "index_123123123121";
			try
			{
				client.DeleteIndex(index);
				client.CreateIndex(index);
			}
			catch (Exception e)
			{
				Console.WriteLine(e);
			}
			var result = client.Bulk(new List<BulkObject>()
			                         	{
			                         		new BulkObject() { Id = "1", Index = index, Type = "type", Fields = fields }, 
											new BulkObject() { Id = "2", Index = index, Type = "type", Fields = fields }, 
											new BulkObject() { Id = "3", Index = index, Type = "type", Fields = fields }
			                         	});
			Assert.AreEqual(true, result.Success);

			client.Refresh();
			var c = client.Count(index, "type", "age:25");
			Assert.AreEqual(3, c);

			result = client.Delete(index, "type", new string[] { "1", "2", "3" });
			Assert.AreEqual(true, result.Success);

			result=client.DeleteIndex(index);
			Assert.AreEqual(true, result.Success);
		}
예제 #2
0
        public void AllInOne()
        {
            string indexType = "v1";

            var dict = new Dictionary <string, object>();

            dict.Add("age", 22);
            var result = client.Index(app, indexType, "key1", dict);

            Assert.AreEqual(true, result.Success);

            var indexItem1 = new IndexItem("testKey");

            indexItem1.Add("age", 21);
            result = client.Index(app, indexItem1);
            Assert.AreEqual(true, result.Success);

            var indexItem = new IndexItem(indexType, "key2");

            indexItem.Add("age", 23);
            result = client.Index(app, indexItem);
            Assert.AreEqual(true, result.Success);

            client.Refresh();
            var count = client.Count(app, indexType, ExpressionEx.Eq("age", 25));

            Assert.AreEqual(0, count);

            count = client.Count(app, indexType, Conditional.Get(ExpressionEx.Eq("age", 22)));
            Assert.AreEqual(1, count);
            count = client.Count(app, indexType, Conditional.Get(ExpressionEx.Eq("age", 23)));
            Assert.AreEqual(1, count);

            count = client.Count(app, indexType, Conditional.Get(ExpressionEx.Between("age", 22, 23, true)));
            Assert.AreEqual(2, count);

            //a coplex example
            var cond1 = Conditional.Get(ExpressionEx.Eq("name", "jack"))
                        .And(ExpressionEx.Between("age", 22, 30))
                        .And(ExpressionEx.Fuzzy("address", "beijing", 1.0f, 4))
                        .And(ExpressionEx.Le("no", 87));
            Conditional cond2 = Conditional.Or(cond1, Conditional.Not(ExpressionEx.Eq("gender", "male")));

            client.Search("index", "type", cond2.Query);
        }