Exemplo n.º 1
0
    public static void AddElasticsearch(
        this IServiceCollection services, IConfiguration configuration)
    {
        var elasticSearchSettings = new ElasticSearchSettings();

        configuration.GetSection(ElasticSearchSettings.Position).Bind(elasticSearchSettings);

        Console.WriteLine(configuration.GetSection(ElasticSearchSettings.Position).ToString());

        Console.WriteLine($"URL: {elasticSearchSettings.url}. Index: {elasticSearchSettings.index}");

        var settings = new ConnectionSettings(new Uri(elasticSearchSettings.url))
                       .DefaultIndex(elasticSearchSettings.index)
                       .DefaultMappingFor <Post>(m => m
                                                 .Ignore(p => p.IsPublished)
                                                 .PropertyName(p => p.ID, "id")
                                                 )
                       .DefaultMappingFor <Comment>(m => m
                                                    .Ignore(c => c.Email)
                                                    .Ignore(c => c.IsAdmin)
                                                    .PropertyName(c => c.ID, "id")
                                                    );

        var client = new ElasticClient(settings);

        services.AddSingleton <IElasticClient>(client);
    }
Exemplo n.º 2
0
        public ElasticIndexer(ElasticSearchSettings settings)
        {
            string uri = settings.Uri;

            Uri    = new Uri("https://" + uri);
            Client = LoadClient();
        }
 public SearchElasticsearch(IOptions <ElasticSearchSettings> elasticsearchSettings)
 {
     _elasticSearchSettings = elasticsearchSettings.Value;
     this._node             = new Uri(_elasticSearchSettings.Url);
     this._settings         = new ConnectionSettings(_node);
     this._client           = new ElasticClient(_settings);
 }
Exemplo n.º 4
0
        private void AddElasticSearch(IServiceCollection services)
        {
            var settings = new ElasticSearchSettings();

            Configuration.GetSection("ElasticSearchSettings").Bind(settings);
            services.AddElasticsearch(settings);
        }
Exemplo n.º 5
0
 public BreweryElasticsearch(IOptions <ElasticSearchSettings> elasticsearchSettings, ILogger <BreweryElasticsearch> logger)
 {
     _elasticSearchSettings = elasticsearchSettings.Value;
     this._node             = new Uri(_elasticSearchSettings.Url);
     this._settings         = new ConnectionSettings(_node);
     this._client           = new ElasticClient(_settings);
     _logger = logger;
 }
 public ElasticSearchJobHistoryStore(ILogger logger, ElasticSearchSettings settings)
 {
     if (logger == null)
     {
         throw new ArgumentNullException(nameof(logger));
     }
     _client = MakeElasticSearchClient(settings);
 }
        private ElasticClient MakeElasticSearchClient(ElasticSearchSettings settings)
        {
            var node         = settings.GetElasticSearchUri();
            var connSettings = new ConnectionSettings(node);

            connSettings.DefaultIndex("fabric-databus");
            return(new ElasticClient(connSettings));
        }
 public BeerStyleElasticsearch(IOptions <ElasticSearchSettings> elasticsearchSettings, ILogger <BeerStyleElasticsearch> logger)
 {
     _elasticSearchSettings = elasticsearchSettings.Value;
     this._node             = new Uri(_elasticSearchSettings.Url);
     this._settings         = new ConnectionSettings(_node);
     _settings.DefaultIndex(_elasticSearchSettings.Index);
     this._client = new ElasticClient(_settings);
     _logger      = logger;
 }
 public UserElasticsearch(IOptions <ElasticSearchSettings> elsaticSearchSettings, ILogger <UserElasticsearch> logger)
 {
     _logger = logger;
     _elasticSearchSettings = elsaticSearchSettings.Value;
     this._node             = new Uri(_elasticSearchSettings.Url);
     this._settings         = new ConnectionSettings(_node);
     this._client           = new ElasticClient(_settings);
     _index = "mb";
 }
Exemplo n.º 10
0
 public BeerService(IOptions <ElasticSearchSettings> elasticsearchSettings, IBeerElasticsearch beerElasticsearch,
                    IBeerRepository beerRepository, IBreweryService breweryService, ICalculation calculation, ILogger <BeerService> logger)
 {
     _elasticsearchSettings = elasticsearchSettings.Value;
     _beerRepository        = beerRepository;
     _breweryService        = breweryService;
     _beerElasticsearch     = beerElasticsearch;
     _calculation           = calculation;
     _logger = logger;
 }
Exemplo n.º 11
0
        public static void AddElasticsearch(this IServiceCollection services, ElasticSearchSettings settings)
        {
            var connectionSettings = new ConnectionSettings(new Uri(settings.Url))
                                     .DefaultIndex(settings.Index)
                                     .DefaultMappingFor <MovieTrailer>(m => m
                                                                       .PropertyName(p => p.Id, "id"));

            var client = new ElasticClient(connectionSettings);

            services.AddSingleton <IElasticClient>(client);
        }
        public static IServiceCollection RegisterConfigurationServices(this IServiceCollection service, HostBuilderContext context)
        {
            var connectionStrings     = new ConnectionStrings();
            var elasticsearchSettings = new ElasticSearchSettings();
            var queueSettings         = new QueueSettings();

            context.Configuration.GetSection("ConnectionStrings").Bind(connectionStrings);
            context.Configuration.GetSection("Elastic").Bind(elasticsearchSettings);
            context.Configuration.GetSection("QueueSettings").Bind(queueSettings);

            service.AddSingleton(elasticsearchSettings);
            service.AddSingleton(queueSettings);
            service.AddSingleton(connectionStrings);

            return(service);
        }
Exemplo n.º 13
0
        private Uri CreateElasticSearchUri(ElasticSearchSettings elasticSearchConfig)
        {
            if (string.IsNullOrEmpty(elasticSearchConfig.Scheme) || string.IsNullOrEmpty(elasticSearchConfig.Server) ||
                string.IsNullOrEmpty(elasticSearchConfig.Port))
            {
                throw new ConfigurationException("You must specify Scheme, Server and Port for elastic search.");
            }

            if (!string.IsNullOrEmpty(elasticSearchConfig.Username) &&
                !string.IsNullOrEmpty(elasticSearchConfig.Password))
            {
                return(new Uri(
                           $"{elasticSearchConfig.Scheme}://{elasticSearchConfig.Username}:{elasticSearchConfig.Password}@{elasticSearchConfig.Server}:{elasticSearchConfig.Port}"));
            }

            return(new Uri($"{elasticSearchConfig.Scheme}://{elasticSearchConfig.Server}:{elasticSearchConfig.Port}"));
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="ElasticSearchReporterSettings" /> class.
        /// </summary>
        public ElasticSearchReporterSettings()
        {
            DataKeys = new MetricValueDataKeys(
                EsConstants.ElasticsearchDefaults.CustomHistogramDataKeys,
                EsConstants.ElasticsearchDefaults.CustomMeterDataKeys);

            ElasticSearchSettings = new ElasticSearchSettings(new Uri("http://localhost:9200"), "metrics");
            HttpPolicy            = new HttpPolicy
            {
                FailuresBeforeBackoff = Constants.DefaultFailuresBeforeBackoff,
                BackoffPeriod         = Constants.DefaultBackoffPeriod,
                Timeout = Constants.DefaultTimeout
            };
            ReportInterval          = TimeSpan.FromSeconds(5);
            MetricNameFormatter     = EsConstants.ElasticsearchDefaults.MetricNameFormatter;
            MetricTagValueFormatter = EsConstants.ElasticsearchDefaults.MetricTagValueFormatter;
        }
Exemplo n.º 15
0
        public static ILogger CreateLogger(LoggingLevelSwitch levelSwitch, ElasticSearchSettings elasticSearchSettings,
                                           string clientName, string applicationName)
        {
            var logPrefix   = $"logstash-{clientName}-{applicationName}";
            var sinkOptions = new ElasticsearchSinkOptions(elasticSearchSettings.GetElasticSearchUri())
            {
                IndexFormat        = logPrefix + "-{0:yyyy.MM.dd}",
                BufferBaseFilename = elasticSearchSettings.BufferBaseFilename
            };

            var loggerConfiguration = new LoggerConfiguration()
                                      .MinimumLevel.ControlledBy(levelSwitch)
                                      .Enrich.FromLogContext()
                                      .WriteTo.ColoredConsole()
                                      .WriteTo.Elasticsearch(sinkOptions);

            return(loggerConfiguration.CreateLogger());
        }
Exemplo n.º 16
0
 public ProductIndexService(IServiceProvider serviceProvider, ILogger <ProductIndexService> logger, ElasticSearchSettings configurationSettings)
 {
     _serviceProvider       = serviceProvider;
     _configurationSettings = configurationSettings;
     _logger = logger;
 }
Exemplo n.º 17
0
 public AppSettings()
 {
     ElasticSearch = new ElasticSearchSettings();
 }
Exemplo n.º 18
0
 public LoggerHelpers(ElasticSearchSettings elasticsearchSettings)
 {
     _elasticsearchSettings = elasticsearchSettings;
 }
 public void GetElasticSearchUri_ValidSettings_CreatesUriSuccessfully(ElasticSearchSettings settings, Uri expectedUri)
 {
     Assert.Equal(expectedUri, settings.GetElasticSearchUri());
 }
 public void GetElasticSearchUri_InvalidSettings_Throws(ElasticSearchSettings elasticSearchSettings)
 {
     Assert.Throws <FabricConfigurationException>(() => elasticSearchSettings.GetElasticSearchUri());
 }