当前位置: 首页>>代码示例>>C#>>正文


C# IElasticClient.Bulk方法代码示例

本文整理汇总了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;
			});
		}
开发者ID:strongant,项目名称:elasticsearch-net,代码行数:30,代码来源:IntegrationSetup.cs

示例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()
			);
		}
开发者ID:radiosterne,项目名称:elasticsearch-net,代码行数:14,代码来源:IntegrationSetup.cs

示例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();
            }
        }
开发者ID:proactima,项目名称:ElasticSearchClient,代码行数:65,代码来源:DataLoader.cs


注:本文中的IElasticClient.Bulk方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。