本文整理汇总了C#中IElasticClient.Index方法的典型用法代码示例。如果您正苦于以下问题:C# IElasticClient.Index方法的具体用法?C# IElasticClient.Index怎么用?C# IElasticClient.Index使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IElasticClient
的用法示例。
在下文中一共展示了IElasticClient.Index方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IndexItems
public static void IndexItems(IElasticClient client)
{
for (var i = 0; i < 5; i++)
{
var j = i + 1;
var person = new Person
{
Id = j,
Firstname = string.Format("Martijn{0}", j),
Lastname = string.Format("{0}Laarman", j)
};
if (ValidateIfIdIsAlreadyUsedForIndex(j, client))
{
client.Index(person);
}
}
}
示例2: TestIndex
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);
}
示例3: CreateRandomBlogs
private static void CreateRandomBlogs(IElasticClient elastic)
{
var blogPosts = new[]
{
new BlogPost {Id = Guid.NewGuid(), Title = "test post 123", Body = "1"},
new BlogPost {Id = Guid.NewGuid(), Title = "test something 123", Body = "2"},
new BlogPost {Id = Guid.NewGuid(), Title = "read this post", Body = "3"},
new BlogPost {Id = Guid.NewGuid(), Title = "read my blog", Body = "4"},
new BlogPost {Id = Guid.NewGuid(), Title = "post from jason", Body = "5"},
new BlogPost {Id = Guid.NewGuid(), Title = "private blog", Body = "6"}
};
foreach (var blogPost in blogPosts)
{
elastic.Index(blogPost, p => p
.Id(blogPost.Id.ToString())
.Refresh());
}
}
示例4: CreatBlogPostBatch
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());
}
}
示例5: CreateNestedBlogs
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");
}