|
1 | 1 | using Elastic.Clients.Elasticsearch; |
2 | | -using Elastic.Clients.Elasticsearch.Options; |
3 | | -using Elastic.Clients.Elasticsearch.Serialization; |
4 | 2 | using Microsoft.Extensions.Configuration; |
5 | 3 | using Microsoft.Extensions.DependencyInjection; |
6 | | - |
7 | | -var config = new ConfigurationBuilder() |
8 | | - .AddJsonFile("appsettings.json") |
9 | | - .Build(); |
| 4 | +using Microsoft.Extensions.Logging; |
10 | 5 |
|
11 | 6 | await using var provider = new ServiceCollection() |
12 | | - .AddSingleton<IConfiguration>(config) |
13 | | - .AddElasticsearchClient() |
14 | | - .Configure<ElasticsearchClientOptions>( |
15 | | - options => |
16 | | - { |
17 | | - options.ConfigureSettings += settings => settings.ThrowExceptions(); |
18 | | - options.SourceSerializer = |
19 | | - settings => new DefaultSourceSerializer(settings, x => x.WriteIndented = true); |
20 | | - }) |
| 7 | + .AddSingleton<IConfiguration>(new ConfigurationBuilder().Build()) |
| 8 | + .AddLogging(x => x.AddConsole()) |
| 9 | + .AddElasticsearchClient(x => x.ThrowExceptions()) |
21 | 10 | .BuildServiceProvider(); |
22 | 11 |
|
23 | 12 | var client = provider.GetRequiredService<ElasticsearchClient>(); |
24 | | - |
25 | | -Console.WriteLine("Node pool is an {0}", client.ElasticsearchClientSettings.NodePool.GetType()); |
26 | | - |
27 | | -foreach (var node in client.ElasticsearchClientSettings.NodePool.Nodes) |
28 | | -{ |
29 | | - Console.WriteLine("Node configured: {0}", node.Uri); |
30 | | -} |
31 | | - |
32 | | -if (client.ElasticsearchClientSettings.Authentication.TryGetAuthorizationParameters(out var credentials)) |
33 | | -{ |
34 | | - Console.WriteLine( |
35 | | - "Credentials: {0} {1}", |
36 | | - client.ElasticsearchClientSettings.Authentication.AuthScheme, |
37 | | - credentials); |
38 | | -} |
| 13 | +await client.PingAsync(); |
0 commit comments