Skip to content

Commit f1c1967

Browse files
committed
Merge branch 'master' of github.com:elasticsearch/elasticsearch-net
2 parents ea98c70 + 92ffafd commit f1c1967

File tree

144 files changed

+1461
-442
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+1461
-442
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<html><head><title>Nest - Building Requests</title><meta http-equiv="cache-control" content="no-cache"/><meta http-equiv="pragma" content="no-cache"/><meta http-equiv="content-type" content="text/html;charset=utf-8"/><meta http-equiv="expires" content="0"/><meta name="description" content="elasticsearch"/><meta name="keywords" content="nest, elasticsearch, .net, client"/><meta name="author" content="martijn laarman"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" type="text/css" href="/styles/normalize.css"/><link rel="stylesheet" type="text/css" href="/styles/layout.css"/><link rel="stylesheet" type="text/css" href="/styles/pygments.css"/><link rel="stylesheet" type="text/css" href="/styles/pygments.css"/><link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css"/><link href="//fonts.googleapis.com/css?family=Ubuntu+Mono|Open+Sans" rel="stylesheet" type="text/css"/><link href="/prettify/prettify.css" type="text/css" rel="stylesheet"/><link href="/prettify/sunburst.css" type="text/css" rel="stylesheet"/><script src="//code.jquery.com/jquery.min.js" type="text/javascript"></script><script type="text/javascript" src="/prettify/prettify.js"></script><script type="text/javascript" src="/prettify/fix_code_tags.js"></script></head><body><div class="wrapper"><header class="header"><div class="actions"><iframe src="//ghbtns.com/github-btn.html?user=elasticsearch&amp;repo=elasticsearch-net&amp;type=fork&amp;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="95" height="20"></iframe><iframe src="//ghbtns.com/github-btn.html?user=elasticsearch&amp;repo=elasticsearch-net&amp;type=watch&amp;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="110" height="20"></iframe></div><img src="/images/elasticsearch-net-nuget-icon.png" width="48" height="48"/><h1>Elasticsearch.Net </h1><p>Documentation</p></header><div class="divide"></div><div class="middle"><div class="container"><main class="content"><h1 id="building-requests">Building Requests</h1>
2+
<p>This section decribes how to build requests to elasticsearch.</p>
3+
<h2 id="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+
<a href="https://github.com/elasticsearch/elasticsearch/tree/master/rest-api-spec/api">the official client rest specification</a>. This specification documents all
6+
the URL&#39;s (paths and querystrings) but does not map any of the API request and response bodies.</p>
7+
<pre><code>client.GetSource(&quot;myindex&quot;,&quot;mytype&quot;,&quot;1&quot;,qs=&gt;qs
8+
.Routing(&quot;routingvalue&quot;)
9+
);
10+
</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>
14+
<pre><code>client.GetSource(&quot;myindex&quot;,&quot;mytype&quot;,&quot;1&quot;,qs=&gt;qs
15+
.Routing(&quot;routingvalue&quot;)
16+
.Add(&quot;key&quot;,&quot;value&quot;)
17+
);
18+
</code></pre><p>The querystring parameter is always optional.</p>
19+
<h2 id="providing-request-body">Providing request body</h2>
20+
<p>Some endpoints need a request body this can be passed in a couple of ways.</p>
21+
<h3 id="string">String</h3>
22+
<pre><code>var myJson = @&quot;{ &quot;&quot;hello&quot;&quot; : &quot;&quot;world&quot;&quot; }&quot;;
23+
client.Index(&quot;myindex&quot;,&quot;mytype&quot;,&quot;1&quot;, myJson);
24+
</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+
<h3 id="-anonymous-object">(Anonymous) Object</h3>
26+
<pre><code>var myJson = new { hello = &quot;world&quot; };
27+
client.Index(&quot;myindex&quot;,&quot;mytype&quot;,&quot;1&quot;, myJson);
28+
</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
30+
http methods.</p>
31+
<h3 id="ienumerable-lt-object-gt-">IEnumerable&lt;object&gt;</h3>
32+
<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 <a href="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 = &quot;test&quot;, _type=&quot;type&quot;, _id = &quot;1&quot; }},
45+
new
46+
{
47+
name = &quot;my object&#39;s name&quot;
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>
53+
</main></div><aside class="left-sidebar"><aside id="menu"><ul><li><a href="/">Home</a></li></ul><ul id="elasticsearch-net"><h4 class="title">Elasticsearch.Net</h4><ul><li><a href="/elasticsearch-net/quick-start.html">Quick Start</a></li><li><a href="/elasticsearch-net/connecting.html">Connecting</a></li><li><a href="/elasticsearch-net/cluster-failover.html">Cluster failover</a></li><li><a href="/elasticsearch-net/building-requests.html" class="selected">Building requests</a></li><li><a href="/elasticsearch-net/handling-responses.html">Handling responses</a></li><li><a href="/elasticsearch-net/errors.html">Errors</a></li></ul></ul><ul id="nest"><h4 class="title">NEST</h4><ul><li><a href="/nest/quick-start.html">Quick Start</a></li><li><a href="/nest/connecting.html">Connecting</a></li><li><a href="/nest/index-type-inference.html">Type/Index Inference</a></li><li><a href="/nest/handling-responses.html">Handling responses</a></li><li><a href="/nest/writing-queries.html">Writing queries</a></li></ul><li><h4><a href="/nest/core/"><i class="fa fa-chevron-right"></i>Core</a></h4></li><li><h4><a href="/nest/indices/aliases.html"><i class="fa fa-chevron-right"></i>Indices</a></h4></li><li><h4><a href="/nest/cluster/health.html"><i class="fa fa-chevron-right"></i>Cluster</a></h4></li><li><h4><a href="/nest/search/basics.html"><i class="fa fa-chevron-right"></i>Search</a></h4></li><li><h4><a href="/nest/facets/handling.html"><i class="fa fa-chevron-right"></i>Facets</a></h4></li><li><h4><a href="/nest/query/text.html"><i class="fa fa-chevron-right"></i>Query DSL</a></h4></li><li><h4><a href="/nest/filter/and.html"><i class="fa fa-chevron-right"></i>Filter DSL</a></h4></li></ul></aside></aside></div><footer class="footer"></footer></div></body></html>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<html><head><title>Nest - Cluster Failover</title><meta http-equiv="cache-control" content="no-cache"/><meta http-equiv="pragma" content="no-cache"/><meta http-equiv="content-type" content="text/html;charset=utf-8"/><meta http-equiv="expires" content="0"/><meta name="description" content="elasticsearch"/><meta name="keywords" content="nest, elasticsearch, .net, client"/><meta name="author" content="martijn laarman"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" type="text/css" href="/styles/normalize.css"/><link rel="stylesheet" type="text/css" href="/styles/layout.css"/><link rel="stylesheet" type="text/css" href="/styles/pygments.css"/><link rel="stylesheet" type="text/css" href="/styles/pygments.css"/><link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css"/><link href="//fonts.googleapis.com/css?family=Ubuntu+Mono|Open+Sans" rel="stylesheet" type="text/css"/><link href="/prettify/prettify.css" type="text/css" rel="stylesheet"/><link href="/prettify/sunburst.css" type="text/css" rel="stylesheet"/><script src="//code.jquery.com/jquery.min.js" type="text/javascript"></script><script type="text/javascript" src="/prettify/prettify.js"></script><script type="text/javascript" src="/prettify/fix_code_tags.js"></script></head><body><div class="wrapper"><header class="header"><div class="actions"><iframe src="//ghbtns.com/github-btn.html?user=elasticsearch&amp;repo=elasticsearch-net&amp;type=fork&amp;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="95" height="20"></iframe><iframe src="//ghbtns.com/github-btn.html?user=elasticsearch&amp;repo=elasticsearch-net&amp;type=watch&amp;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="110" height="20"></iframe></div><img src="/images/elasticsearch-net-nuget-icon.png" width="48" height="48"/><h1>Elasticsearch.Net </h1><p>Documentation</p></header><div class="divide"></div><div class="middle"><div class="container"><main class="content"><h1 id="connection-pooling-cluster-failover">Connection pooling &amp; Cluster failover</h1>
2+
<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+
<h2 id="configuring">Configuring</h2>
6+
<p>Configuring how the registered <code>IConnectionPool</code> should behave happens on the <code>IConnectionConfigurationValues</code> passed to client
7+
<a href="/elasticsearch-net/connecting.html">see the section on connecting </a></p>
8+
<pre><code>var settings = new ConnectionConfiguration(connectionPool)
9+
.SniffOnConnectionFault(false)
10+
.SniffOnStartup(false)
11+
.SniffLifeSpan(TimeSpan.FromMinutes(1));
12+
</code></pre><h4 id="sniffonconnectionfault-">SniffOnConnectionFault()</h4>
13+
<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+
<h4 id="sniffonstartup-">SniffOnStartup()</h4>
16+
<p>Should the connection pool sniff the cluster state the first time its instantiated. Defaults to false.</p>
17+
<h4 id="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+
<h4 id="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>
21+
<h4 id="setmaxdeadtimeout-">SetMaxDeadTimeout()</h4>
22+
<p>Sets the maximum time a node may be marked dead.</p>
23+
<h4 id="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&#39;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>
26+
<h4 id="setmaxretries-int-retries-">SetMaxRetries(int retries)</h4>
27+
<p>By default an <code>IConnectionPool</code> itself will decide how many times to retry (usually all the registered nodes) if you wish to
28+
limit this you can explicitly tell the connection pool to never retry more then <code>retries</code>.</p>
29+
<h2 id="sniffingconnectionpool">SniffingConnectionPool</h2>
30+
<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);
32+
</code></pre><h2 id="staticconnectionpool">StaticConnectionPool</h2>
33+
<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
36+
<a href="http://en.wikipedia.org/wiki/Noop">NOOP</a></p>
37+
<pre><code>var pool = new StaticConnectionPool(seedUris);
38+
</code></pre></main></div><aside class="left-sidebar"><aside id="menu"><ul><li><a href="/">Home</a></li></ul><ul id="elasticsearch-net"><h4 class="title">Elasticsearch.Net</h4><ul><li><a href="/elasticsearch-net/quick-start.html">Quick Start</a></li><li><a href="/elasticsearch-net/connecting.html">Connecting</a></li><li><a href="/elasticsearch-net/cluster-failover.html" class="selected">Cluster failover</a></li><li><a href="/elasticsearch-net/building-requests.html">Building requests</a></li><li><a href="/elasticsearch-net/handling-responses.html">Handling responses</a></li><li><a href="/elasticsearch-net/errors.html">Errors</a></li></ul></ul><ul id="nest"><h4 class="title">NEST</h4><ul><li><a href="/nest/quick-start.html">Quick Start</a></li><li><a href="/nest/connecting.html">Connecting</a></li><li><a href="/nest/index-type-inference.html">Type/Index Inference</a></li><li><a href="/nest/handling-responses.html">Handling responses</a></li><li><a href="/nest/writing-queries.html">Writing queries</a></li></ul><li><h4><a href="/nest/core/"><i class="fa fa-chevron-right"></i>Core</a></h4></li><li><h4><a href="/nest/indices/aliases.html"><i class="fa fa-chevron-right"></i>Indices</a></h4></li><li><h4><a href="/nest/cluster/health.html"><i class="fa fa-chevron-right"></i>Cluster</a></h4></li><li><h4><a href="/nest/search/basics.html"><i class="fa fa-chevron-right"></i>Search</a></h4></li><li><h4><a href="/nest/facets/handling.html"><i class="fa fa-chevron-right"></i>Facets</a></h4></li><li><h4><a href="/nest/query/text.html"><i class="fa fa-chevron-right"></i>Query DSL</a></h4></li><li><h4><a href="/nest/filter/and.html"><i class="fa fa-chevron-right"></i>Filter DSL</a></h4></li></ul></aside></aside></div><footer class="footer"></footer></div></body></html>

0 commit comments

Comments
 (0)