Пример #1
0
 public void Index(TestModel2 data, string indexName)
 {
     //写入数据,指定索引
     _client.Index(data, s => s.Index(indexName));
     //指定索引、类型
     //_client.Index(data, s => s.Index(indexName).Type("TestModel"));
 }
Пример #2
0
 public void Index(TestModel2 data, string indexName)
 {
     try
     {
         //写入数据,指定索引
         _client.Index(data, s => s.Index(indexName));
         //指定索引、类型
         _client.Index(data, s => s.Index(indexName).Type("TestModel2"));
     }
     catch (Exception ex1)
     {
         var ex = (ElasticsearchClientException)ex1;
         //
         string msg = ex.Response.ServerError.Error.Reason;
         Console.WriteLine(msg);
     }
 }
Пример #3
0
        public void Update(string indexName, int id, TestModel2 model)
        {
            //完整更新
            DocumentPath <TestModel2> path = new DocumentPath <TestModel2>(id);
            var response = _client.Update(path, (p) => p.Index(indexName).Doc(model));
            //或
            //IUpdateRequest<TestModel2, TestModel2> request = new UpdateRequest<TestModel2, TestModel2>(path)
            //{
            //    Doc = new TestModel2()
            //    {
            //        Name = "test4update........"
            //    }
            //};
            //response = _client.Update<TestModel2, TestModel2>(request);

            //局部更新
            //IUpdateRequest<TestModel2, TestModel2P> request1 = new UpdateRequest<TestModel2, TestModel2P>(path)
            //{
            //    Doc = new TestModel2P()
            //    {
            //        Name = "test4update........"
            //    }

            //};
            //response = _client.Update(request1);
            ////或
            //IUpdateRequest<TestModel2, object> request2 = new UpdateRequest<TestModel2, object>(path)
            //{
            //    Doc = new
            //    {
            //        Name = "test4update........"
            //    }

            //};
            //response = _client.Update(request2);
        }