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>This section decribes how to build requests to elasticsearch.</p>
3
+
<h2id="calling-an-api-endpoint">Calling an API endpoint</h2>
4
+
<p><code>Elasticsearch.Net</code> maps <strong>all</strong> the <code>Elasticsearch</code> API endpoints to methods. The reason it can do this is because all these methods are generated from
5
+
<ahref="https://github.com/elasticsearch/elasticsearch/tree/master/rest-api-spec/api">the official client rest specification</a>. This specification documents all
6
+
the URL's (paths and querystrings) but does not map any of the API request and response bodies.</p>
</code></pre><p>Which will do a <code>GET</code> request on <code>/myindex/mytype/1/_source?routing=routingvalue</code>.
11
+
All the methods and arguments are fully documented based in the documentation of the specification. </p>
12
+
<p>As you can see <code>Elasticsearch.Net</code> also strongly types the querystring parameters it knows exist on an endpoint with full intellisense documentation.
13
+
Unknown querystring parameters can still be added:</p>
</code></pre><p>This will call <code>POST</code> on <code>/myindex/mytype/1</code> with the provided string <code>myJson</code> passed verbatim as request body</p>
25
+
<h3id="-anonymous-object">(Anonymous) Object</h3>
26
+
<pre><code>var myJson = new { hello = "world" };
</code></pre><p>This will call <code>POST</code> on <code>/myindex/mytype/1</code> where <code>myJson</code> will be serialized by the registered <code>ISerializer</code></p>
29
+
<p><strong>side note:</strong> if you need <code>PUT</code> semantics <code>IndexPut()</code> also exists. <code>Elasticsearch.Net</code> exposes all the endpoints with all the allowed
<p>Some api endpoints in elasticsearch follow a strict special json format. </p>
33
+
<pre><code>line_of_json_with_no_enters \n
34
+
json_payload_with_enters
35
+
line_of_json_with_no_enters \n
36
+
json_payload_with_enters
37
+
line_of_json_with_no_enters \n
38
+
json_payload_with_enters
39
+
.....
40
+
</code></pre><p>Examples of such endpoints are the <ahref="http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html#docs-bulk">bulk api</a></p>
41
+
<p>in <code>Elasticsearch.Net</code> you can call these with</p>
42
+
<pre><code>var bulk = new object[]
43
+
{
44
+
new { index = new { _index = "test", _type="type", _id = "1" }},
45
+
new
46
+
{
47
+
name = "my object's name"
48
+
}
49
+
};
50
+
client.Bulk(bulk);
51
+
</code></pre><p><code>Elasticsearch.Net</code> will know not to serialize the passed object as <code>[]</code> but instead serialize each seperately and joining them up with <code>\n</code>.
52
+
No request in <code>Elasticsearch</code> expects an array as root object for the request.</p>
<p>One of the major benefits of <code>elasticsearch</code> is that it can handle dying and respawning nodes.
3
+
As long as enough nodes agree that the cluster is healthy, the cluster will continue to operate.
4
+
<code>Elasticsearch.net</code> comes with builtin support to handle falling over to a different node when the requested node failed.</p>
5
+
<h2id="configuring">Configuring</h2>
6
+
<p>Configuring how the registered <code>IConnectionPool</code> should behave happens on the <code>IConnectionConfigurationValues</code> passed to client
7
+
<ahref="/elasticsearch-net/connecting.html">see the section on connecting </a></p>
8
+
<pre><code>var settings = new ConnectionConfiguration(connectionPool)
<p>Should the connection pool resniff the cluster state everytime an operation on a node throws an exception or a faulty http status code.
14
+
Defaults to false.</p>
15
+
<h4id="sniffonstartup-">SniffOnStartup()</h4>
16
+
<p>Should the connection pool sniff the cluster state the first time its instantiated. Defaults to false.</p>
17
+
<h4id="snifflifespan-">SniffLifeSpan()</h4>
18
+
<p>When set will cause the connectionpool to resniff whenever it notices the last sniff information happened too long ago. Defaults to null.</p>
19
+
<h4id="setdeadtimeout-">SetDeadTimeout()</h4>
20
+
<p>Sets the timeout before a node is retried. The default <code>DateTimeProvider</code> will increment this timeout exponentially based on the number of attempts.</p>
<p>Sets the maximum time a node may be marked dead.</p>
23
+
<h4id="disablepings-">DisablePings()</h4>
24
+
<p>By default before a previously dead node is retried a short ping will be send to the node to make sure the node will respond.
25
+
The reason for a separate call is that a ping will call an elasticsearch endpoint that won't stress the JVM. If a node is having issues retrying a possible heavy search operation on it might cause the request to fail later rather then asap. This setting allows you to disable these pings before retries.</p>
<p>This <code>IConnectionPool</code> implementation will <code>sniff</code> the cluster state on the passed seed nodes to find all the alive nodes in the cluster. It will round robin requests over all the alive nodes it knows about. </p>
31
+
<pre><code>var pool = new SniffingConnectionPool(seedUris);
<p>This <code>IConnectionPool</code> implementation will round robin over the provided nodes. When nodes are dead it will mark it dead with an incremental timeout before
34
+
retrying requests on that node. When all the known nodes are marked dead an operation will be tried once on a random node from the list. </p>
35
+
<p>The difference between this implementation and <code>SniffingConnectionPool</code> is that this implementation effectively treats the <code>Sniff()</code> call as a
0 commit comments