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


C# ElasticClient.Bulk方法代码示例

本文整理汇总了C#中Nest.ElasticClient.Bulk方法的典型用法代码示例。如果您正苦于以下问题:C# ElasticClient.Bulk方法的具体用法?C# ElasticClient.Bulk怎么用?C# ElasticClient.Bulk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nest.ElasticClient的用法示例。


在下文中一共展示了ElasticClient.Bulk方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanDeserializeNestedBulkError

		public void CanDeserializeNestedBulkError()
		{
			var nestedCausedByError = @"{
			   ""took"": 4,
			   ""errors"": true,
			   ""items"": [{
					""update"": {
						""_index"": ""index-name"",
						""_type"": ""type-name"",
						""_id"": ""1"",
						""status"": 400,
						""error"": {
							""type"": ""illegal_argument_exception"",
							""reason"": ""failed to execute script"",
							""caused_by"": {
								""type"": ""script_exception"",
								""reason"": ""failed to run inline script [use(java.lang.Exception) {throw new Exception(\""Customized Exception\"")}] using lang [groovy]"",
								""caused_by"": {
									""type"": ""privileged_action_exception"",
									""reason"": null,
									""caused_by"": {
										""type"": ""exception"",
										""reason"": ""Custom Exception""
									}
								}
							}
						}
					}
				}]
			}";

			var bytes = Encoding.UTF8.GetBytes(nestedCausedByError);
			var connection = new InMemoryConnection(bytes);
			var settings = new ConnectionSettings(new SingleNodeConnectionPool(new Uri("http://localhost:9200")), connection);
			var client = new ElasticClient(settings);

			var bulkResponse = client.Bulk(new BulkDescriptor());

			bulkResponse.Errors.Should().BeTrue();

			var firstOperation = bulkResponse.ItemsWithErrors.First();

			firstOperation.Error.Should().NotBeNull();
			firstOperation.Error.CausedBy.Should().NotBeNull();
			firstOperation.Error.CausedBy.InnerCausedBy.Should().NotBeNull();
			firstOperation.Error.CausedBy.InnerCausedBy.InnerCausedBy.Should().NotBeNull();
		}
开发者ID:niemyjski,项目名称:elasticsearch-net,代码行数:47,代码来源:GithubIssue2152.cs

示例2: Setup

        public static void Setup()
        {
            var client = new ElasticClient(ElasticsearchConfiguration.Settings(hostOverride: new Uri("http://localhost:9200")));

            //uncomment the next line if you want to see the setup in fiddler too
            //var client = ElasticsearchConfiguration.Client;

            var projects = NestTestData.Data;
            var people = NestTestData.People;
            var boolTerms = NestTestData.BoolTerms;

            var createIndexResult = client.CreateIndex(ElasticsearchConfiguration.DefaultIndex, c => c
                .NumberOfReplicas(0)
                .NumberOfShards(1)
                .AddMapping<ElasticsearchProject>(m => m
                .MapFromAttributes()
                .Properties(p => p
                .String(s => s.Name(ep => ep.Content).TermVector(TermVectorOption.with_positions_offsets_payloads))))
                .AddMapping<Person>(m => m.MapFromAttributes())
                .AddMapping<BoolTerm>(m => m.Properties(pp=>pp
                    .String(sm => sm.Name(p => p.Name1).Index(FieldIndexOption.not_analyzed))
                    .String(sm => sm.Name(p => p.Name2).Index(FieldIndexOption.not_analyzed))
                ))
            );

            var createAntotherIndexResult = client.CreateIndex(ElasticsearchConfiguration.DefaultIndex + "_clone", c => c
                .NumberOfReplicas(0)
                .NumberOfShards(1)
                .AddMapping<ElasticsearchProject>(m => m
                .MapFromAttributes()
                .Properties(p => p
                .String(s => s.Name(ep => ep.Content).TermVector(TermVectorOption.with_positions_offsets_payloads))))
                .AddMapping<Person>(m => m.MapFromAttributes())
                .AddMapping<BoolTerm>(m => m.Properties(pp => pp
                    .String(sm => sm.Name(p => p.Name1).Index(FieldIndexOption.not_analyzed))
                    .String(sm => sm.Name(p => p.Name2).Index(FieldIndexOption.not_analyzed))
                ))
            );

            var bulkResponse = client.Bulk(b=>b
                .IndexMany(projects)
                .IndexMany(people)
                .IndexMany(boolTerms)
                .Refresh()
            );
        }
开发者ID:herqueles3,项目名称:elasticsearch-net,代码行数:46,代码来源:IntegrationSetup.cs

示例3: LogData

        public string LogData()
        {
            string result = string.Empty;
            try
            {
                List<VODDetails> objList = new List<VODDetails>();

                objList = DAL.FetchData();

                #region ElasticSearch --Begin
                string indexName = "test";
                string typeName = "test01";
                var node = new Uri("http://localhost:9200");
                var settings = new ConnectionSettings(node);
                var client = new ElasticClient(settings);
                BulkDescriptor objbulk = new BulkDescriptor();
                foreach (var value in objList)
                {
                    objbulk.Index<object>(i => i
                        .Index(indexName)
                        .Type(typeName)
                        .Id(value.strAssetID)
                        .Document(value));
                    client.Bulk(objbulk);
                }

                result = "Data successfully inserted";
                #endregion ElasticSearch  --End
            }

            catch (Exception ex)
            {
                result = ex.Message;
            }

            return result;
        }
开发者ID:navilwayne,项目名称:QuantumTVChannelSubs,代码行数:37,代码来源:Service1.svc.cs

示例4: transmitBulkData

        //
        // Send the messages to Elasticsearch (bulk)
        //
        private DateTime transmitBulkData(IEnumerable<JObject> bulkItems, string bulkIndexName, string bulkTypeName,
            ElasticClient client, DateTime lastFlushTime, List<JObject> messages)
        {
            var bulkRequest = new BulkRequest() {Refresh = true};
            bulkRequest.Operations = new List<IBulkOperation>();
            foreach (var json in bulkItems)
            {
                // ES requires a timestamp, add one if not present
                var ts = json["@timestamp"];
                if (ts == null)
                    json["@timestamp"] = DateTime.UtcNow;
                var bi = new BulkIndexOperation<JObject>(json);
                bi.Index = bulkIndexName;
                bi.Type = bulkTypeName;
                bulkRequest.Operations.Add(bi);
            }

            // The total messages processed for this operation.
            int numMessages = bulkItems.Count();

            var response = client.Bulk(bulkRequest);
            if (!response.IsValid)
            {
                LogManager.GetCurrentClassLogger().Error("Failed to send: {0}", response);
                Interlocked.Increment(ref _errorCount);
                interlockedInsert(messages);  // Put the messages back into the queue
            }
            else // Success!
            {
                lastFlushTime = DateTime.UtcNow;
                LogManager.GetCurrentClassLogger()
                    .Info("Successfully sent {0} messages in a single bulk request", numMessages);
                Interlocked.Add(ref _sentMessages, numMessages);
            }

            // Remove them from the working list
            messages.RemoveRange(0, numMessages);
            return lastFlushTime;
        }
开发者ID:bbqchickenrobot,项目名称:TimberWinR,代码行数:42,代码来源:Elasticsearch.cs


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