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); }
public void TestBulkIndexWithParentId() { var client = new ElasticSearchClient("localhost"); var fields = new Dictionary <string, object>(); fields.Add("name", "jack"); fields.Add("age", 25); var index = "index_12312312311"; 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", ParentId = "1", JsonData = jsondata }, new BulkObject() { Id = "2", Index = index, Type = "type", ParentId = "1", JsonData = jsondata }, new BulkObject() { Id = "3", Index = index, Type = "type", ParentId = "1", JsonData = jsondata } }); 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" }, "1"); Assert.AreEqual(true, result.Success); client.Refresh(); c = client.Count(index, "type", "age:25"); Assert.AreEqual(0, c); client.DeleteIndex(index); }
public void Clean() { _elasticSearchClient.Delete(_fileData); }