Skip to content

Commit ec85362

Browse files
authored
Add ElasticsearchConfiguration for managing transport setup (#165)
Introduce `ElasticsearchConfiguration` to configure how the transport connects and interacts with Elasticsearch, including support for Elastic Cloud setups. This enables flexible connection options via URIs, Cloud IDs, and various authentication mechanisms. This makes it semantically cleaner to create a transport for Elasticsearch.
1 parent eeed2ad commit ec85362

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System;
6+
7+
namespace Elastic.Transport.Products.Elasticsearch;
8+
9+
/// <summary>
10+
/// Allows you to control how <see cref="ITransport{TConfiguration}"/> behaves and where/how it connects to Elasticsearch
11+
/// </summary>
12+
public record ElasticsearchConfiguration : TransportConfiguration
13+
{
14+
/// <summary>
15+
/// Creates a new instance of <see cref="ElasticsearchConfiguration"/>
16+
/// </summary>
17+
/// <param name="uri">The root of the Elastic stack product node we want to connect to. Defaults to http://localhost:9200</param>
18+
public ElasticsearchConfiguration(Uri? uri = null)
19+
: base(new SingleNodePool(uri ?? new Uri("http://localhost:9200")), productRegistration: ElasticsearchProductRegistration.Default ) { }
20+
21+
/// <summary>
22+
/// Sets up the client to communicate to Elastic Cloud using <paramref name="cloudId"/>,
23+
/// <para><see cref="CloudNodePool"/> documentation for more information on how to get your Cloud ID</para>
24+
/// </summary>
25+
public ElasticsearchConfiguration(string cloudId, BasicAuthentication credentials)
26+
: base(new CloudNodePool(cloudId, credentials), productRegistration: ElasticsearchProductRegistration.Default) { }
27+
28+
/// <summary>
29+
/// Sets up the client to communicate to Elastic Cloud using <paramref name="cloudId"/>,
30+
/// <para><see cref="CloudNodePool"/> documentation for more information on how to get your Cloud ID</para>
31+
/// </summary>
32+
public ElasticsearchConfiguration(string cloudId, ApiKey credentials)
33+
: base(new CloudNodePool(cloudId, credentials), productRegistration: ElasticsearchProductRegistration.Default) { }
34+
35+
/// <summary> Sets up the client to communicate to Elastic Cloud.</summary>
36+
public ElasticsearchConfiguration(Uri cloudEndpoint, BasicAuthentication credentials)
37+
: base(new CloudNodePool(cloudEndpoint, credentials), productRegistration: ElasticsearchProductRegistration.Default) { }
38+
39+
/// <summary> Sets up the client to communicate to Elastic Cloud. </summary>
40+
public ElasticsearchConfiguration(Uri cloudEndpoint, ApiKey credentials)
41+
: base(new CloudNodePool(cloudEndpoint, credentials), productRegistration: ElasticsearchProductRegistration.Default) { }
42+
43+
}

0 commit comments

Comments
 (0)