DeleteIndex() 공개 메소드

public DeleteIndex ( string index ) : ElasticSearch.Client.Domain.OperateResult
index string
리턴 ElasticSearch.Client.Domain.OperateResult
		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 TestCreateParentChildType()
        {
            var index = "index_test_parent_child_type";

			

            var parentType = new TypeSetting("blog");
            parentType.AddStringField("title");

            var client = new ElasticSearchClient("localhost");
        	
			client.CreateIndex(index);

            var op= client.PutMapping(index, parentType);

            Assert.AreEqual(true,op.Acknowledged);

            var childType = new TypeSetting("comment",parentType);
            childType.AddStringField("comments");

            op=client.PutMapping(index,childType);
            Assert.AreEqual(true, op.Acknowledged);

            var mapping=client.GetMapping(index, "comment");

            Assert.True(mapping.IndexOf("_parent")>0);

            client.DeleteIndex(index);
        }
예제 #3
0
		public void SimpleTests()
		{
			var indexName = "myindex_" + Guid.NewGuid();
			var indexType = "type";

			var client = new ElasticSearchClient("localhost");

			var result = client.Index(indexName, indexType, "testkey", "{\"a\":\"b\",\"c\":\"d\"}");
			Assert.AreEqual(true, result.Success);

			client.Refresh(indexName);

			var doc = client.Search(indexName, indexType, "c:d");
			Console.WriteLine(doc.Response);
			Assert.AreEqual(1, doc.GetHits().Hits.Count);
			Assert.AreEqual("b", doc.GetHits().Hits[0].Source["a"]);

			client.Delete(indexName, indexType, "testkey");

			client.Refresh(indexName);

			var doc1 = client.Get(indexName, indexType, "testkey");
			Assert.AreEqual(null,doc1);

			client.DeleteIndex(indexName);
		}
예제 #4
0
		static void Main(string[] args)
		{
			var client = new ElasticSearchClient("10.129.8.58",9500,TransportType.Thrift);
			int failure = 0;

			var data = "{\"book\": \"The Hitchhiker's Guide to the Galaxy\"" +
                ",\"id\":"+1+
			           ",\"chapter\": \"Chapter 11\",\"text1\": \"All the doors in this spaceship have a cheerful and sunny disposition. It is their pleasure to open for you, and their satisfaction to close again with the knowledge of a job well done.\"}";
			client.Index("benchmark_test", "default", Guid.NewGuid().ToString(), data);

			int count = int.Parse(args[0]);

			var begin = DateTime.Now;
			for (var i = 0; i < count; i++)
			{
                data = "{\"book\": \"The Hitchhiker's Guide to the Galaxy\"" +
                ",\"id\":" + i +
                       ",\"chapter\": \"Chapter 11\",\"text1\": \"All the doors in this spaceship have a cheerful and sunny disposition. It is their pleasure to open for you, and their satisfaction to close again with the knowledge of a job well done.\"}";
                client.Index("benchmark_test", "default", Guid.NewGuid().ToString(), data);

				var response = client.Index("benchmark_test", "default", Guid.NewGuid().ToString(), data);
				if (!response.Success)
				{
					failure++;
				}
			}
			var end = DateTime.Now;

			var timespan = end - begin;

			var avg = timespan.TotalMilliseconds / count;
			Console.WriteLine("iteration:{0},failure:{3},elapsed time:{1},avg time:{2}ms", count, timespan, avg, failure);

			client.DeleteIndex("benchmark_test");

			Console.Write("Press any key to continue . . . ");
			Console.ReadKey(true);
		}
        public void TestHighlight()
         {
             ElasticSearch.Client.ElasticSearchClient client=new ElasticSearchClient("localhost",9200,TransportType.Http);


             string indexName = Guid.NewGuid().ToString();


             client.CreateIndex(indexName);


             TypeSetting type=new TypeSetting("type");
             type.AddStringField("title").Analyzer = "whitespace";
             type.AddStringField("snippet").Analyzer = "whitespace";
             client.PutMapping(indexName, type);

             //index sample
             Dictionary<string, object> dict=new Dictionary<string, object>();
             dict["title"] = "quick fox jump away";
             dict["snippet"] = "quick fox jump away,where are you?";
             client.Index(indexName, "type", "1", dict);
             
             dict=new Dictionary<string, object>();
             dict["title"] = "fox river is nearby";
             dict["snippet"] = "where is fox river,where is it?";
             client.Index(indexName, "type", "2", dict);

   
             ElasticQuery query=new ElasticQuery(
                 new QueryStringQuery("fox")
                 .AddField("title",5)
                 .AddField("snippet",5),null,0,5 );

             query.AddHighlightField(new HightlightField("title"));
             query.AddHighlightField(new HightlightField("snippet"));

             client.Refresh(indexName);

             var result= client.Search(indexName, query);
             Console.Out.WriteLine(result.Query);
             Console.Out.WriteLine(result.Response);

             Console.Out.WriteLine("---");
             HitStatus hits = result.GetHits();
             if (hits != null)
                 foreach (var o in hits.Hits)
                 {
                     foreach (var pair in o.Highlight)
                     {
                         Console.Out.WriteLine(pair.Key + ":");
                         foreach (var field in pair.Value)
                         {
                             Console.Out.WriteLine(field);
                         }

                         Console.Out.WriteLine();
                     }
                 
                 }


             client.DeleteIndex(indexName);
         }
예제 #6
0
 public void CleanUp()
 {
     client.DeleteIndex(app);
 }
		public void TestBulkForFramdThrift()
		{
			var client = new ElasticSearchClient("localhost");

			var fields = new Dictionary<string, object>();
			fields.Add("name", "jack");
			fields.Add("age", 25);
			var index = "index_bulk_framed";
			try
			{
				client.DeleteIndex(index);
				client.CreateIndex(index);
			}
			catch (Exception e)
			{
				Console.WriteLine(e);
			}
			var jsondata = JsonSerializer.Get(fields);

			var result = client.Bulk(new List<BulkObject>()
			                                               	{
			                                               		new BulkObject() { Id = "1", Index = index, Type = "type", JsonData = jsondata }, 
			                                               		new BulkObject() { Id = "2", Index = index, Type = "type", JsonData = jsondata }, 
			                                               		new BulkObject() { Id = "3", Index = index, Type = "type", JsonData = jsondata }, 
																new BulkObject() { Id = "4", Index = index, Type = "type", JsonData = jsondata }, 
																new BulkObject() { Id = "5", Index = index, Type = "type",ParentId = "1", JsonData = jsondata },
																new BulkObject() { Id = "6", Index = index, Type = "type",ParentId = "1", JsonData = jsondata },
																new BulkObject() { Id = "7", Index = index, Type = "type",ParentId = "1", JsonData = jsondata },
																new BulkObject() { Id = "8", Index = index, Type = "type",ParentId = "1", JsonData = jsondata },
			                                               	});
			Assert.AreEqual(true, result.Success);
		}