From b22e28e4a059eae761f1a9c8f91227587cbd8c33 Mon Sep 17 00:00:00 2001 From: Kyle McClellan Date: Thu, 10 Aug 2023 19:46:03 -0500 Subject: [PATCH] Example: Ping localhost --- ...stretch.DependencyInjection.Example.csproj | 6 +--- .../Program.cs | 35 +++---------------- .../appsettings.json | 17 --------- 3 files changed, 6 insertions(+), 52 deletions(-) delete mode 100644 Elasticstretch.DependencyInjection.Example/appsettings.json diff --git a/Elasticstretch.DependencyInjection.Example/Elasticstretch.DependencyInjection.Example.csproj b/Elasticstretch.DependencyInjection.Example/Elasticstretch.DependencyInjection.Example.csproj index d25dc93..b1143df 100644 --- a/Elasticstretch.DependencyInjection.Example/Elasticstretch.DependencyInjection.Example.csproj +++ b/Elasticstretch.DependencyInjection.Example/Elasticstretch.DependencyInjection.Example.csproj @@ -13,12 +13,8 @@ - - - - - + diff --git a/Elasticstretch.DependencyInjection.Example/Program.cs b/Elasticstretch.DependencyInjection.Example/Program.cs index f8d490c..96254ef 100644 --- a/Elasticstretch.DependencyInjection.Example/Program.cs +++ b/Elasticstretch.DependencyInjection.Example/Program.cs @@ -1,38 +1,13 @@ using Elastic.Clients.Elasticsearch; -using Elastic.Clients.Elasticsearch.Options; -using Elastic.Clients.Elasticsearch.Serialization; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; - -var config = new ConfigurationBuilder() - .AddJsonFile("appsettings.json") - .Build(); +using Microsoft.Extensions.Logging; await using var provider = new ServiceCollection() - .AddSingleton(config) - .AddElasticsearchClient() - .Configure( - options => - { - options.ConfigureSettings += settings => settings.ThrowExceptions(); - options.SourceSerializer = - settings => new DefaultSourceSerializer(settings, x => x.WriteIndented = true); - }) + .AddSingleton(new ConfigurationBuilder().Build()) + .AddLogging(x => x.AddConsole()) + .AddElasticsearchClient(x => x.ThrowExceptions()) .BuildServiceProvider(); var client = provider.GetRequiredService(); - -Console.WriteLine("Node pool is an {0}", client.ElasticsearchClientSettings.NodePool.GetType()); - -foreach (var node in client.ElasticsearchClientSettings.NodePool.Nodes) -{ - Console.WriteLine("Node configured: {0}", node.Uri); -} - -if (client.ElasticsearchClientSettings.Authentication.TryGetAuthorizationParameters(out var credentials)) -{ - Console.WriteLine( - "Credentials: {0} {1}", - client.ElasticsearchClientSettings.Authentication.AuthScheme, - credentials); -} +await client.PingAsync(); diff --git a/Elasticstretch.DependencyInjection.Example/appsettings.json b/Elasticstretch.DependencyInjection.Example/appsettings.json deleted file mode 100644 index 200682f..0000000 --- a/Elasticstretch.DependencyInjection.Example/appsettings.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "Elasticsearch": { - "NodeUris": [ - "https://node1.example.com:9200", - "https://node2.example.com:9200", - "https://node3.example.com:9200", - "https://node4.example.com:9200", - "https://node5.example.com:9200" - ], - "Credentials": { - "ApiKeyId": "elasticstretch", - "ApiKey": "abcdef12345" - }, - "UseSniffing": true, - "Randomize": true - } -}