You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>Connecting to Elasticsearch with <code>Elasticsearch.Net</code> is quite easy but has a few toggles and options worth knowing.</p>
4
4
<h2id="choosing-the-right-connection-strategy">Choosing the right connection strategy</h2>
5
-
<p>If you simply new an <code>ElasticsearchClient</code> it will be a non-failover connection to <code>http://localhost:9200</code></p>
5
+
<p>If you simply new an <code>ElasticsearchClient</code>, it will be a non-failover connection to <code>http://localhost:9200</code></p>
6
6
<pre><code>var client = new ElasticsearchClient();
7
-
</code></pre><p>If your elasticsearch node does not live at <code>http://localhost:9200</code> but i.e <code>http://mynode.example.com:8082/apiKey</code>
8
-
you will need to pass in some <code>IConnectionConfigurationValues</code> the easiest way to do this is:</p>
7
+
</code></pre><p>If your Elasticsearch node does not live at <code>http://localhost:9200</code> but i.e <code>http://mynode.example.com:8082/apiKey</code>, then
8
+
you will need to pass in some instance of <code>IConnectionConfigurationValues</code>.</p>
9
+
<p>The easiest way to do this is:</p>
9
10
<pre><code>var node = new Uri("http://mynode.example.com:8082/apiKey");
10
11
var config = new ConnectionConfiguration(node);
11
12
var client = new ElasticsearchClient(config);
12
13
</code></pre><p>This however is still a non-failover connection. Meaning if that <code>node</code> goes down the operation will not be retried on any other nodes in the cluster.</p>
13
-
<p>To get a failover connection we have to pass an <code>IConnectionPool</code> instead of a <code>Uri</code>.</p>
14
+
<p>To get a failover connection we have to pass an <code>IConnectionPool</code>instance instead of a <code>Uri</code>.</p>
14
15
<pre><code>var node = new Uri("http://mynode.example.com:8082/apiKey");
15
16
var connectionPool = new SniffingConnectionPool(new[] { node });
16
17
var config = new ConnectionConfiguration(connectionPool);
17
18
var client = new ElasticsearchClient(config);
18
19
</code></pre><p>Here instead of directly passing <code>node</code>, we pass a <code>SniffingConnectionPool</code> which will use our <code>node</code> to find out the rest of the available cluster nodes.
19
20
Be sure to read more about <ahref="/elasticsearch-net/cluster-failover.html">Connection Pooling and Cluster Failover here</a></p>
20
21
<h2id="options">Options</h2>
21
-
<p>Besides either passing a <code>Uri</code> or <code>IConnectionPool</code>on the constructor of <code>ConnectionConfiguration</code>, you can also fluently control many more options.</p>
22
+
<p>Besides either passing a <code>Uri</code> or <code>IConnectionPool</code>to <code>ConnectionConfiguration</code>, you can also fluently control many more options. For instance:</p>
22
23
<pre><code>var config = new ConnectionConfiguration(connectionPool)
<p>Enable compressed responses from Elasticsearch (Note that nodes need to be configured to allow this. See the <ahref="http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-http.html">http module settings</a> for more info).</p>
<p>As an alternative to the C/go like error checking on <code>response.IsValid</code>, you can instead tell the client to always throw an <code>ElasticsearchServerException</code> when a call resulted in an exception on the Elasticsearch server. Reasons for such exceptions could be search parser errors and index missing exceptions.</p>
<p>Appends <code>pretty=true</code> 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 <code>SetGlobalQueryStringParameters</code>.</p>
<p>Sets the HTTP basic authentication credentials to specify with all requests.</p>
64
+
<p><strong>Note:</strong> This can alternatively be specified on the node URI directly:</p>
65
+
<pre><code>var uri = new Uri("http://username:password@localhost:9200");
66
+
var config = new ConnectionConfiguration(uri);
67
+
</code></pre><p>...but may become tedious when using connection pooling with multiple nodes.</p>
68
+
<h2id="configuring-ssl">Configuring SSL</h2>
69
+
<p>SSL must be configured outside of the client using .NET's <ahref="http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager%28v=vs.110%29.aspx">ServicePointManager</a> class and setting the <ahref="http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback.aspx">ServerCertificateValidationCallback</a> property.</p>
70
+
<p>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 <code>true</code>:</p>
</code></pre><p>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.</p>
Copy file name to clipboardExpand all lines: docs/node_modules/wintersmith-livereload/node_modules/livereload-server/node_modules/livereload-protocol/package.json
Copy file name to clipboardExpand all lines: docs/node_modules/wintersmith-livereload/node_modules/livereload-server/node_modules/websocket.io/node_modules/ws/node_modules/commander/package.json
Copy file name to clipboardExpand all lines: docs/node_modules/wintersmith-livereload/node_modules/livereload-server/node_modules/websocket.io/node_modules/ws/node_modules/options/package.json
Copy file name to clipboardExpand all lines: docs/node_modules/wintersmith-livereload/node_modules/livereload-server/node_modules/websocket.io/node_modules/ws/node_modules/tinycolor/.npmignore
Copy file name to clipboardExpand all lines: docs/node_modules/wintersmith-livereload/node_modules/livereload-server/node_modules/websocket.io/node_modules/ws/node_modules/tinycolor/package.json
Copy file name to clipboardExpand all lines: docs/node_modules/wintersmith-livereload/node_modules/livereload-server/node_modules/websocket.io/node_modules/ws/package.json
Copy file name to clipboardExpand all lines: docs/node_modules/wintersmith-livereload/node_modules/livereload-server/node_modules/websocket.io/package.json
0 commit comments