private static void AddOperationDocument(InnerBulkOperation operation, StringBuilder sb) { string json = JsonConvert.SerializeObject(operation.Document); sb.Append(json); sb.Append("\n"); }
private static void AddOperationMetadata(InnerBulkOperation operation, StringBuilder sb) { var indexParams = new Dictionary <string, string>(operation.IndexOperationParams) { { "_index", operation.IndexName }, { "_type", operation.IndexType }, }; var paramStrings = indexParams.Where(kv => kv.Value != null) .Select(kv => string.Format(@"""{0}"" : ""{1}""", kv.Key, kv.Value)); var documentMetadata = string.Join(",", paramStrings.ToArray()); sb.AppendFormat(@"{{ ""index"" : {{ {0} }} }}", documentMetadata); sb.Append("\n"); }
private static void AddOperationMetadata(InnerBulkOperation operation, StringBuilder sb) { if (operation.DocumentId != null) { sb.AppendFormat( @"{{ ""index"" : {{ ""_index"" : ""{0}"", ""_type"" : ""{1}"", ""_id"" : ""{2}""}} }}", operation.IndexName, operation.IndexType, operation.DocumentId); } else { sb.AppendFormat( @"{{ ""index"" : {{ ""_index"" : ""{0}"", ""_type"" : ""{1}""}} }}", operation.IndexName, operation.IndexType); } sb.Append("\n"); }
/// <summary> /// Prepare the event and add it to the BulkDescriptor. /// </summary> /// <param name="logEvent"></param> private void PrepareAndAddToBulk(Dictionary <string, object> logEvent) { ElasticFilters.PrepareEvent(logEvent); var indexName = _indexName.Format(logEvent).ToLower(); var indexType = _indexType.Format(logEvent); var operation = new InnerBulkOperation { Document = logEvent, IndexName = indexName, IndexType = indexType }; lock (_bulk) { _bulk.Add(operation); } }