static public TelemetryPipe SendToElasticSearch(this TelemetryPipe pipe, ElasticSearchOutputConfig config)
        {
            var esOutput = new ElasticSearchOutput(config);

            pipe.RegisterProcessor(esOutput.Process);
            return(pipe);
        }
        public ElasticSearchOutput(ElasticSearchOutputConfig config, PutIndexTemplateDescriptor indexTemplate = null)
        {
            _logger = LogProvider.For <ElasticSearchOutput>();

            _logger.Info("Creating");

            var connectionSettings = new ConnectionSettings(new Uri(config.ElasticSearchUri))
                                     .RequestTimeout(config.RetryInterval)
                                     .MaximumRetries(config.RetryCount);

            _elasticClient = new ElasticClient(connectionSettings);

            var batchCount = config.MaxBatchCount > 0 ? config.MaxBatchCount : 1;

            _uploadBlock = new ActionBlock <IList <TelemetryEvent> >(list => Send(list, throwExceptions: false), new ExecutionDataflowBlockOptions
            {
                BoundedCapacity        = config.BoundedCapacity,
                MaxDegreeOfParallelism = config.MaxDegreeOfParallelism,
            });

            _internalStreamBufferSubscription = _internalStream
                                                .Buffer(TimeSpan.FromSeconds(config.BufferTimeSec), batchCount)
                                                .Subscribe(_uploadBlock.AsObserver());

            _jsonSerializerSettings = new JsonSerializerSettings()
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            _elasticClient.PutIndexTemplate(indexTemplate ?? new PutIndexTemplateDescriptor(config.ElasticSearchIndexName + "-template")
                                            .Template(config.ElasticSearchIndexName + "*")
                                            .Settings(x => x
                                                      .NumberOfReplicas(0)
                                                      .NumberOfShards(1))
                                            .Mappings(m => m
                                                      .Map("_default_", tm => tm
                                                           .AllField(af => af.Enabled(false))
                                                           .DynamicTemplates(d => d
                                                                             .DynamicTemplate("all_strings_not_analyzed", dd => dd
                                                                                              .MatchMappingType("string")
                                                                                              .Match("*")
                                                                                              .Mapping(dm => dm
                                                                                                       .String(sm => sm
                                                                                                               .NotAnalyzed()))))
                                                           .Properties(p => p
                                                                       .String(sp => sp
                                                                               .Name("message")
                                                                               .Index(FieldIndexOption.Analyzed))))));


            _config = config;
        }
        public ElasticSearchOutput(ElasticSearchOutputConfig config, PutIndexTemplateDescriptor indexTemplate = null)
        {
            _logger = LogProvider.For<ElasticSearchOutput>();

            _logger.Info("Creating");

            var connectionSettings = new ConnectionSettings(new Uri(config.ElasticSearchUri))
                .RequestTimeout(config.RetryInterval)
                .MaximumRetries(config.RetryCount);

            _elasticClient = new ElasticClient(connectionSettings);

            var batchCount = config.MaxBatchCount > 0 ? config.MaxBatchCount : 1;

            _uploadBlock = new ActionBlock<IList<TelemetryEvent>>(list => Send(list, throwExceptions: false), new ExecutionDataflowBlockOptions
            {
                BoundedCapacity = config.BoundedCapacity,
                MaxDegreeOfParallelism = config.MaxDegreeOfParallelism,
            });

            _internalStreamBufferSubscription = _internalStream
                .Buffer(TimeSpan.FromSeconds(config.BufferTimeSec), batchCount)
                .Subscribe(_uploadBlock.AsObserver());

            _jsonSerializerSettings = new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver() };

            _elasticClient.PutIndexTemplate(indexTemplate ?? new PutIndexTemplateDescriptor(config.ElasticSearchIndexName+"-template")
                .Template(config.ElasticSearchIndexName+"*")
                .Settings(x => x
                    .NumberOfReplicas(0)
                    .NumberOfShards(1))
                .Mappings(m => m
                    .Map("_default_", tm => tm
                        .AllField(af => af.Enabled(false))
                        .DynamicTemplates(d => d
                            .DynamicTemplate("all_strings_not_analyzed", dd => dd
                                .MatchMappingType("string")
                                .Match("*")
                                .Mapping(dm => dm
                                    .String(sm => sm
                                        .NotAnalyzed()))))
                        .Properties(p => p
                            .String(sp => sp
                                .Name("message")
                                .Index(FieldIndexOption.Analyzed))))));

            
            _config = config;
        }
 static public TelemetryPipe SendToElasticSearch(this TelemetryPipe pipe, ElasticSearchOutputConfig config)
 {
     var esOutput = new ElasticSearchOutput(config);
     pipe.RegisterProcessor(esOutput.Process);
     return pipe;
 }