本文整理汇总了C#中IElasticClient.Bulk方法的典型用法代码示例。如果您正苦于以下问题:C# IElasticClient.Bulk方法的具体用法?C# IElasticClient.Bulk怎么用?C# IElasticClient.Bulk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IElasticClient
的用法示例。
在下文中一共展示了IElasticClient.Bulk方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IndexDemoData
public static void IndexDemoData(IElasticClient client, string index = null)
{
index = index ?? ElasticsearchConfiguration.DefaultIndex;
var projects = NestTestData.Data;
var people = NestTestData.People;
var boolTerms = NestTestData.BoolTerms;
var parents = NestTestData.Parents;
var children = NestTestData.Children;
var bulkResponse = client.Bulk(b => {
b.FixedPath(index);
b.IndexMany(projects);
b.IndexMany(people);
b.IndexMany(boolTerms);
var rand = new Random();
foreach (var parent in parents)
b.Index<Parent>(i => i.Document(parent));
foreach (var child in children)
b.Index<Child>(i => i
.Document(child)
.Parent(parents[rand.Next(parents.Count)].Id)
);
b.Refresh();
return b;
});
}
示例2: IndexDemoData
public static void IndexDemoData(IElasticClient client, string index = null)
{
index = index ?? ElasticsearchConfiguration.DefaultIndex;
var projects = NestTestData.Data;
var people = NestTestData.People;
var boolTerms = NestTestData.BoolTerms;
var bulkResponse = client.Bulk(b => b
.FixedPath(index)
.IndexMany(projects)
.IndexMany(people)
.IndexMany(boolTerms)
.Refresh()
);
}
示例3: LoadData
public static void LoadData(IElasticClient client)
{
var r = client.CreateIndex("entities", c => c
.AddMapping<JsonObject>(m => m
.IdField(i => i.SetIndex("not_analyzed"))
.TypeName("locations")
.Properties(p => p
.String(s => s.Name("id"))
.String(s => s.Name("name").Index(FieldIndexOption.analyzed).IndexAnalyzer("standard"))
.String(s => s.Name("parentId")))
));
var all = new List<JsonObject>();
var reader = new StreamReader(File.OpenRead(@"c:\temp\countries.csv"), new UTF8Encoding());
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
if (line == null) continue;
var values = line.Split(',');
values[2] = values[2].Replace("\"", "");
var location = CreateObject.CreateMiniEntity(values[0], values[1], values[2]);
all.Add(location);
}
var allObjects = all.ToDictionary(json => json.Id);
foreach (var item in all)
{
var path = new List<string>();
if (!String.IsNullOrEmpty(item["parentId"].ToString()))
{
RecGetParent(path, allObjects, item);
path.Reverse();
path.Add(item["name"].ToString());
item.Add("fullPath", String.Join("#.#", path));
}
else
item.Add("fullPath", String.Empty);
}
var insertCount = 0;
var bulker = new BulkDescriptor();
for (var index = 0; index < all.Count; index++)
{
var item = all[index];
bulker.Index<JsonObject>(op =>
op.Index("entities")
.Id(Convert.ToString(item["id"]))
.Type("locations")
.Object(item));
insertCount++;
if (insertCount != 1000 && index != (all.Count - 1)) continue;
//PushToElastic(client, bulker);
var result = client.Bulk(bulker);
insertCount = 0;
bulker = new BulkDescriptor();
}
}