private static IEnumerable <Func <object> > DocumentCommands(IElasticClient elastic) { return(new List <Func <object> > { () => elastic.Bulk( new BulkRequest("test_index") { Operations = new List <IBulkOperation> { new BulkCreateOperation <Post>(new Post { Id = 1, Title = "BulkCreateOperation" }) } }), () => elastic.Create(new CreateRequest <Post>(new Post { Id = 2, Title = "CreateRequest" }, "test_index")), () => elastic.CreateDocument(new Post { Id = 3, Title = "CreateDocument" }), () => elastic.Count <Post>(), () => elastic.Search <Post>(s => s.MatchAll()), () => elastic.DeleteByQuery(new DeleteByQueryRequest("test_index") { Size = 0 }) }); }
public bool CreateIndex(ActivityIndex index) { var response = _elasticClient.CreateDocument(index); var result = response.IsValid; if (result) { _logger.LogInformation($"活动 {index.Title} 索引创建成功"); } return(result); }
public void CreateDocument() { var user = new User { Id = IDUtils.NewId(), Name = DateTimeOffset.Now.ToString("yyyyMMddHHmmssfff") }; var request = new CreateRequest <User>(user.Id); var response = _client.CreateDocument(user); Assert.True(response.ApiCall.Success); }