Skip to content

Commit 8df6283

Browse files
committed
Docs: Add section for configuring SSL and SetBasicAuthentication option
Closes #1081
1 parent 40ccb72 commit 8df6283

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

docs/contents/elasticsearch-net/connecting.md

+34-7
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@ Connecting to Elasticsearch with `Elasticsearch.Net` is quite easy but has a few
1111

1212
## Choosing the right connection strategy
1313

14-
If you simply new an `ElasticsearchClient` it will be a non-failover connection to `http://localhost:9200`
14+
If you simply new an `ElasticsearchClient`, it will be a non-failover connection to `http://localhost:9200`
1515

1616
var client = new ElasticsearchClient();
1717

18-
If your elasticsearch node does not live at `http://localhost:9200` but i.e `http://mynode.example.com:8082/apiKey`
19-
you will need to pass in some `IConnectionConfigurationValues` the easiest way to do this is:
18+
If your Elasticsearch node does not live at `http://localhost:9200` but i.e `http://mynode.example.com:8082/apiKey`, then
19+
you will need to pass in some instance of `IConnectionConfigurationValues`.
20+
21+
The easiest way to do this is:
2022

2123
var node = new Uri("http://mynode.example.com:8082/apiKey");
2224
var config = new ConnectionConfiguration(node);
2325
var client = new ElasticsearchClient(config);
2426

2527
This however is still a non-failover connection. Meaning if that `node` goes down the operation will not be retried on any other nodes in the cluster.
2628

27-
To get a failover connection we have to pass an `IConnectionPool` instead of a `Uri`.
29+
To get a failover connection we have to pass an `IConnectionPool` instance instead of a `Uri`.
2830

2931
var node = new Uri("http://mynode.example.com:8082/apiKey");
3032
var connectionPool = new SniffingConnectionPool(new[] { node });
@@ -34,14 +36,18 @@ To get a failover connection we have to pass an `IConnectionPool` instead of a `
3436
Here instead of directly passing `node`, we pass a `SniffingConnectionPool` which will use our `node` to find out the rest of the available cluster nodes.
3537
Be sure to read more about [Connection Pooling and Cluster Failover here](/elasticsearch-net/cluster-failover.html)
3638

37-
3839
## Options
3940

40-
Besides either passing a `Uri` or `IConnectionPool` on the constructor of `ConnectionConfiguration`, you can also fluently control many more options.
41+
Besides either passing a `Uri` or `IConnectionPool` to `ConnectionConfiguration`, you can also fluently control many more options. For instance:
4142

4243
var config = new ConnectionConfiguration(connectionPool)
4344
.EnableTrace()
44-
.ExposeRawResponse(shouldExposeRawResponse);
45+
.ExposeRawResponse()
46+
.SetBasicAuthentication("user", "pass")
47+
.SetTimeout(5000)
48+
...
49+
50+
The following is a list of available connection configuration options:
4551

4652
### DisableAutomaticProxyDetection
4753
Disable automatic proxy detection. Defaults to true.
@@ -89,3 +95,24 @@ As an alternative to the C/go like error checking on `response.IsValid`, you can
8995

9096
### UsePrettyResponses
9197
Appends `pretty=true` to all the requests. Handy if you are debugging or listening to the requests with i.e fiddler. This setting can be safely used in conjuction with `SetGlobalQueryStringParameters`.
98+
99+
### SetBasicAuthentication
100+
Sets the HTTP basic authentication credentials to specify with all requests.
101+
102+
**Note:** This can alternatively be specified on the node URI directly:
103+
104+
var uri = new Uri("http://username:password@localhost:9200");
105+
var config = new ConnectionConfiguration(uri);
106+
107+
...but may become tedious when using connection pooling with multiple nodes.
108+
109+
## Configuring SSL
110+
111+
SSL must be configured outside of the client using .NET's [ServicePointManager](http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager%28v=vs.110%29.aspx
112+
) class and setting the [ServerCertificateValidationCallback](http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback.aspx) property.
113+
114+
The bare minimum to make .NET accept self-signed SSL certs that are not in the Window's CA store would be to have the callback simply return `true`:
115+
116+
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, errors) => true;
117+
118+
However, this will accept all requests from the AppDomain to untrusted SSL sites, therefore we recommend doing some minimal introspection on the passed in certificate.

0 commit comments

Comments
 (0)