-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22bc76e
commit b22e28e
Showing
3 changed files
with
6 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IConfiguration>(config) | ||
.AddElasticsearchClient() | ||
.Configure<ElasticsearchClientOptions>( | ||
options => | ||
{ | ||
options.ConfigureSettings += settings => settings.ThrowExceptions(); | ||
options.SourceSerializer = | ||
settings => new DefaultSourceSerializer(settings, x => x.WriteIndented = true); | ||
}) | ||
.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build()) | ||
.AddLogging(x => x.AddConsole()) | ||
.AddElasticsearchClient(x => x.ThrowExceptions()) | ||
.BuildServiceProvider(); | ||
|
||
var client = provider.GetRequiredService<ElasticsearchClient>(); | ||
|
||
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(); |
17 changes: 0 additions & 17 deletions
17
Elasticstretch.DependencyInjection.Example/appsettings.json
This file was deleted.
Oops, something went wrong.