當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。