class Person { public int id { get; set; } public int gender { get; set; } public string name { get; set; } public DateTime birthday { get; set; } }
private void Search() { try { var settings = new ConnectionConfiguration(new Uri("http://localhost:9200/")).RequestTimeout(TimeSpan.FromMinutes(2)); var lowlevelClient = new ElasticLowLevelClient(settings); var searchResponse = lowlevelClient.Search<StringResponse>("people", PostData.Serializable(new { from = 0, size = 10, query = new { match = new { gender = 0 } } })); var successful = searchResponse.Success; var responseJson = searchResponse.Body; } catch (Exception exception) { } } private void Add() { var person = new Person { id=1,gender = 0,name = "张伶俐",birthday = DateTime.Now.AddYears(-10) }; try { var settings = new ConnectionConfiguration(new Uri("http://localhost:9200/")).RequestTimeout(TimeSpan.FromMinutes(2)); var lowlevelClient = new ElasticLowLevelClient(settings); var ndexResponse = lowlevelClient.Index<BytesResponse>("people", "1", PostData.Serializable(person)); byte[] responseBytes = ndexResponse.Body; } catch (Exception ex) {} }
可用直接调用 get http://localhost:9200/people/_search?q=gender:0 搜索也可以出现结果