private static void CreatBlogPostBatch(IElasticClient elastic) { for (var index = 0; index < 10; index++) { var blogPost = new BlogPost { Id = Guid.NewGuid(), Title = $"title {index:000}", Body = $"This is {index:000} very long blog post!" }; elastic.Index(blogPost, p => p .Id(blogPost.Id.ToString()) .Refresh()); } }
private static void TestIndex(IElasticClient elastic) { var blogPost = new BlogPost { Id = Guid.NewGuid(), Title = "First blog post", Body = "This is very long blog post!" }; var firstId = blogPost.Id; var indexResult = elastic.Index(blogPost, p => p .Id(blogPost.Id.ToString()) .Refresh()); Console.WriteLine(indexResult.ApiCall.Success); var resDel = elastic.Delete<BlogPost>(firstId.ToString()); Console.WriteLine(resDel.ApiCall.Success); }
private static void CreateNestedBlogs(IElasticClient elastic) { var author1 = new Author {Id = Guid.NewGuid(), FirstName = "John", LastName = "Doe"}; var author2 = new Author {Id = Guid.NewGuid(), FirstName = "Notjohn", LastName = "Doe"}; var author3 = new Author {Id = Guid.NewGuid(), FirstName = "John", LastName = "Notdoe"}; var blogPosts = new[] { new BlogPost {Id = Guid.NewGuid(), Title = "test post 1", Body = "1", Author = author1}, new BlogPost {Id = Guid.NewGuid(), Title = "test post 2", Body = "2", Author = author2}, new BlogPost {Id = Guid.NewGuid(), Title = "test post 3", Body = "3", Author = author3} }; foreach (var blogPost in blogPosts) { elastic.Index(blogPost, p => p .Id(blogPost.Id.ToString()) .Refresh()); } //add blog with missing property var author4 = new Author { Id = Guid.NewGuid(), FirstName = "John", LastName = "Doe" }; var blogPost1 = new BlogPost { Id = Guid.NewGuid(), Title = "test post 1", Body = null, Author = author4 }; elastic.Index(blogPost1, p => p .Id(blogPost1.Id.ToString()) .Refresh()); Console.WriteLine("Nested blogs indexed"); }