初始化实例
nuget安装
1、单点连接
var node = new Uri("http://myserver:9200");
var settings = new ConnectionSettings(node);
var client = new ElasticClient(settings);
2、连接池连接
var nodes = new Uri[]
{
new Uri("http://myserver1:9200"),
new Uri("http://myserver2:9200"),
new Uri("http://myserver3:9200")
};
var pool = new StaticConnectionPool(nodes);
var settings = new ConnectionSettings(pool);
var client = new ElasticClient(settings);
3、指定索引
可以通过ConnectionSettings使用.DefaultIndex(),来指定默认索引。当一个请求里没有指定具体索引时,NEST将请求默认索引。
var settings = new ConnectionSettings()
.DefaultIndex("defaultindex");
新增
var nodes = new Uri[]
{
new Uri("http://localhost:9200")
};
var pool = new StaticConnectionPool(nodes);
var settings = new ConnectionSettings(pool).DefaultIndex("crm.base.log").BasicAuthentication("elastic", "caKBawShu0Pm7BsjSFbd");
var client = new ElasticClient(settings);
var log = new CreateRequest
log.Document = new CRMLog();
log.Document.LogLevel = ;
log.Document.HttpMethod = "Get";
client.Create
删除
根据ID删除
client.Delete
client.Delete(new DeleteRequest("crm.base.log", "4bd0ffb9-f5fc-4748-94f6-b41c706cc4ca"));
删除多条
var bulkDel = new BulkRequest() { Operations = new List
bulkDel.Operations.Add(new BulkDeleteOperation
bulkDel.Operations.Add(new BulkDeleteOperation
var resultDel = client.Bulk(bulkDel);
从新指定索引
client.Delete
修改
IUpdateRequest
{
Doc = new CRMLog()
{
LogLevel = ,
HttpMethod = "test4update…….."
}
};
var resp = client.Update
更新多条
var bulkUpdate = new BulkRequest() { Operations = new List
bulkUpdate.Operations.Add(new BulkUpdateOperation
bulkUpdate.Operations.Add(new BulkUpdateOperation
var result = client.Bulk(bulkUpdate);
查询
var modUser = client.Get
var tweet = JsonConvert.SerializeObject(modUser.Source);
多查询
var modList = client.Search
.From()
.Size()
.Query(q =>
q.Term(t => t.HttpMethod, "www.b.com")
|| q.Match(mq => mq.Field(f => f.HttpMethod).Query("Get"))
)
);
重新指定索引
client.Search
推荐链接
https://blog.csdn.net/manimanihome/article/details/55682494
手机扫一扫
移动阅读更方便
你可能感兴趣的文章