/** * The following is a list of available connection configuration options: */ public void AvailableOptions() { var config = new ConnectionConfiguration() .DisableAutomaticProxyDetection() // <1> Disable automatic proxy detection. When called, defaults to `true`. .EnableHttpCompression() // <2> Enable compressed request and responses from Elasticsearch (Note that nodes need to be configured to allow this. See the {ref_current}/modules-http.html[http module settings] for more info). .DisableDirectStreaming(); // <3> By default responses are deserialized directly from the response stream to the object you tell it to. For debugging purposes, it can be very useful to keep a copy of the raw response on the result object, which is what calling this method will do. var client = new ElasticLowLevelClient(config); var result = client.Search <SearchResponse <object> >(new { size = 12 }); /** `.ResponseBodyInBytes` will only have a value if the client configuration has `DisableDirectStreaming` set */ var raw = result.ResponseBodyInBytes; /** * Please note that using `.DisableDirectStreaming` only makes sense if you need the mapped response **and** the raw response __at the same time__. * If you need only a `string` response simply call */ var stringResult = client.Search <string>(new { }); /** * and similarly, if you need only a `byte[]` */ var byteResult = client.Search <byte[]>(new { }); /** other configuration options */ config = config .GlobalQueryStringParameters(new NameValueCollection()) // <1> Allows you to set querystring parameters that have to be added to every request. For instance, if you use a hosted elasticserch provider, and you need need to pass an `apiKey` parameter onto every request. .Proxy(new Uri("http://myproxy"), "username", "pass") // <2> Sets proxy information on the connection. .RequestTimeout(TimeSpan.FromSeconds(4)) // <3> [[request-timeout]] Sets the global maximum time a connection may take. Please note that this is the request timeout, the builtin .NET `WebRequest` has no way to set connection timeouts (see http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.timeout(v=vs.110).aspx[the MSDN documentation on `HttpWebRequest.Timeout` Property]). .ThrowExceptions() // <4> As an alternative to the C/go like error checking on `response.IsValid`, you can instead tell the client to <<thrown-exceptions, throw exceptions>>. .PrettyJson() // <5> forces all serialization to be indented and appends `pretty=true` to all the requests so that the responses are indented as well .BasicAuthentication("username", "password"); // <6> sets the HTTP basic authentication credentials to specify with all requests. /** * NOTE: Basic authentication credentials can alternatively be specified on the node URI directly: */ var uri = new Uri("http://*****:*****@localhost:9200"); var settings = new ConnectionConfiguration(uri); /** *...but this may become tedious when using connection pooling with multiple nodes. * * [[thrown-exceptions]] * === Exceptions * There are three categories of exceptions that may be thrown: * * `ElasticsearchClientException`:: These are known exceptions, either an exception that occurred in the request pipeline * (such as max retries or timeout reached, bad authentication, etc...) or Elasticsearch itself returned an error (could * not parse the request, bad query, missing field, etc...). If it is an Elasticsearch error, the `ServerError` property * on the response will contain the the actual error that was returned. The inner exception will always contain the * root causing exception. * * `UnexpectedElasticsearchClientException`:: These are unknown exceptions, for instance a response from Elasticsearch not * properly deserialized. These are sometimes bugs and {github}/issues[should be reported]. This exception also inherits from `ElasticsearchClientException` * so an additional catch block isn't necessary, but can be helpful in distinguishing between the two. * * Development time exceptions:: These are CLR exceptions like `ArgumentException`, `ArgumentOutOfRangeException`, etc. * that are thrown when an API in the client is misused. The `.ThrowExceptions()` setting has no bearing on these as * they will always be thrown, and also should not be handled by a consumer. * */ }
/** * The following is a list of available connection configuration options: */ public void AvailableOptions() { //hide var client = new ElasticsearchClient(); //endhide var config = new ConnectionConfiguration() .DisableAutomaticProxyDetection() /** Disable automatic proxy detection. Defaults to true. */ .EnableHttpCompression() /** * Enable compressed request and reesponses from Elasticsearch (Note that nodes need to be configured * to allow this. See the [http module settings](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-http.html) for more info). */ .DisableDirectStreaming() /** * By default responses are deserialized off stream to the object you tell it to. * For debugging purposes it can be very useful to keep a copy of the raw response on the result object. */; var result = client.Search<SearchResponse<object>>(new { size = 12 }); var raw = result.ResponseBodyInBytes; /** This will only have a value if the client configuration has ExposeRawResponse set */ /** * Please note that this only make sense if you need a mapped response and the raw response at the same time. * If you need a `string` or `byte[]` response simply call: */ var stringResult = client.Search<string>(new { }); //hide config = config //endhide .GlobalQueryStringParameters(new NameValueCollection()) /** * Allows you to set querystring parameters that have to be added to every request. For instance, if you use a hosted elasticserch provider, and you need need to pass an `apiKey` parameter onto every request. */ .Proxy(new Uri("http://myproxy"), "username", "pass") /** Sets proxy information on the connection. */ .RequestTimeout(TimeSpan.FromSeconds(4)) /** * Sets the global maximum time a connection may take. * Please note that this is the request timeout, the builtin .NET `WebRequest` has no way to set connection timeouts * (see http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.timeout(v=vs.110).aspx). */ .ThrowExceptions() /** * As an alternative to the C/go like error checking on `response.IsValid`, you can instead tell the client to throw * exceptions. * * There are three category of exceptions thay may be thrown: * * 1) ElasticsearchClientException: These are known exceptions, either an exception that occurred in the request pipeline * (such as max retries or timeout reached, bad authentication, etc...) or Elasticsearch itself returned an error (could * not parse the request, bad query, missing field, etc...). If it is an Elasticsearch error, the `ServerError` property * on the response will contain the the actual error that was returned. The inner exception will always contain the * root causing exception. * * 2) UnexpectedElasticsearchClientException: These are unknown exceptions, for instance a response from Elasticsearch not * properly deserialized. These are usually bugs and should be reported. This excpetion also inherits from ElasticsearchClientException * so an additional catch block isn't necessary, but can be helpful in distinguishing between the two. * * 3) Development time exceptions: These are CLR exceptions like ArgumentException, NullArgumentException etc... that are thrown * when an API in the client is misused. These should not be handled as you want to know about them during development. * */ .PrettyJson() /** * Forces all serialization to be indented and appends `pretty=true` to all the requests so that the responses are indented as well */ .BasicAuthentication("username", "password") /** Sets the HTTP basic authentication credentials to specify with all requests. */; /** * **Note:** This can alternatively be specified on the node URI directly: */ var uri = new Uri("http://*****:*****@localhost:9200"); var settings = new ConnectionConfiguration(uri); /** * ...but may become tedious when using connection pooling with multiple nodes. */ }
/** * The following is a list of available connection configuration options: */ public void AvailableOptions() { //hide var client = new ElasticLowLevelClient(); //endhide var config = new ConnectionConfiguration() .DisableAutomaticProxyDetection() /** Disable automatic proxy detection. Defaults to true. */ .EnableHttpCompression() /** * Enable compressed request and reesponses from Elasticsearch (Note that nodes need to be configured * to allow this. See the [http module settings](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-http.html) for more info). */ .DisableDirectStreaming() /** * By default responses are deserialized off stream to the object you tell it to. * For debugging purposes it can be very useful to keep a copy of the raw response on the result object. */; var result = client.Search <SearchResponse <object> >(new { size = 12 }); var raw = result.ResponseBodyInBytes; /** This will only have a value if the client configuration has ExposeRawResponse set */ /** * Please note that this only make sense if you need a mapped response and the raw response at the same time. * If you need a `string` or `byte[]` response simply call: */ var stringResult = client.Search <string>(new { }); //hide config = config //endhide .GlobalQueryStringParameters(new NameValueCollection()) /** * Allows you to set querystring parameters that have to be added to every request. For instance, if you use a hosted elasticserch provider, and you need need to pass an `apiKey` parameter onto every request. */ .Proxy(new Uri("http://myproxy"), "username", "pass") /** Sets proxy information on the connection. */ .RequestTimeout(TimeSpan.FromSeconds(4)) /** * Sets the global maximum time a connection may take. * Please note that this is the request timeout, the builtin .NET `WebRequest` has no way to set connection timeouts * (see http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.timeout(v=vs.110).aspx). */ .ThrowExceptions() /** * As an alternative to the C/go like error checking on `response.IsValid`, you can instead tell the client to throw * exceptions. * * There are three category of exceptions thay may be thrown: * * 1) ElasticsearchClientException: These are known exceptions, either an exception that occurred in the request pipeline * (such as max retries or timeout reached, bad authentication, etc...) or Elasticsearch itself returned an error (could * not parse the request, bad query, missing field, etc...). If it is an Elasticsearch error, the `ServerError` property * on the response will contain the the actual error that was returned. The inner exception will always contain the * root causing exception. * * 2) UnexpectedElasticsearchClientException: These are unknown exceptions, for instance a response from Elasticsearch not * properly deserialized. These are usually bugs and should be reported. This excpetion also inherits from ElasticsearchClientException * so an additional catch block isn't necessary, but can be helpful in distinguishing between the two. * * 3) Development time exceptions: These are CLR exceptions like ArgumentException, NullArgumentException etc... that are thrown * when an API in the client is misused. These should not be handled as you want to know about them during development. * */ .PrettyJson() /** * Forces all serialization to be indented and appends `pretty=true` to all the requests so that the responses are indented as well */ .BasicAuthentication("username", "password") /** Sets the HTTP basic authentication credentials to specify with all requests. */; /** * **Note:** This can alternatively be specified on the node URI directly: */ var uri = new Uri("http://*****:*****@localhost:9200"); var settings = new ConnectionConfiguration(uri); /** * ...but may become tedious when using connection pooling with multiple nodes. */ }
/** * The following is a list of available connection configuration options: */ public void AvailableOptions() { var config = new ConnectionConfiguration() .DisableAutomaticProxyDetection() // <1> Disable automatic proxy detection. When called, defaults to `true`. .EnableHttpCompression() // <2> Enable compressed request and responses from Elasticsearch (Note that nodes need to be configured to allow this. See the {ref_current}/modules-http.html[http module settings] for more info). .DisableDirectStreaming(); // <3> By default responses are deserialized directly from the response stream to the object you tell it to. For debugging purposes, it can be very useful to keep a copy of the raw response on the result object, which is what calling this method will do. var client = new ElasticLowLevelClient(config); var result = client.Search<SearchResponse<object>>(new { size = 12 }); /** `.ResponseBodyInBytes` will only have a value if the client configuration has `DisableDirectStreaming` set */ var raw = result.ResponseBodyInBytes; /** * Please note that using `.DisableDirectStreaming` only makes sense if you need the mapped response **and** the raw response __at the same time__. * If you need only a `string` response simply call */ var stringResult = client.Search<string>(new { }); /** * and similarly, if you need only a `byte[]` */ var byteResult = client.Search<byte[]>(new { }); /** other configuration options */ config = config .GlobalQueryStringParameters(new NameValueCollection()) // <1> Allows you to set querystring parameters that have to be added to every request. For instance, if you use a hosted elasticserch provider, and you need need to pass an `apiKey` parameter onto every request. .Proxy(new Uri("http://myproxy"), "username", "pass") // <2> Sets proxy information on the connection. .RequestTimeout(TimeSpan.FromSeconds(4)) // <3> [[request-timeout]] Sets the global maximum time a connection may take. Please note that this is the request timeout, the builtin .NET `WebRequest` has no way to set connection timeouts (see http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.timeout(v=vs.110).aspx[the MSDN documentation on `HttpWebRequest.Timeout` Property]). .ThrowExceptions() // <4> As an alternative to the C/go like error checking on `response.IsValid`, you can instead tell the client to <<thrown-exceptions, throw exceptions>>. .PrettyJson() // <5> forces all serialization to be indented and appends `pretty=true` to all the requests so that the responses are indented as well .BasicAuthentication("username", "password"); // <6> sets the HTTP basic authentication credentials to specify with all requests. /** * NOTE: Basic authentication credentials can alternatively be specified on the node URI directly: */ var uri = new Uri("http://*****:*****@localhost:9200"); var settings = new ConnectionConfiguration(uri); /** *...but this may become tedious when using connection pooling with multiple nodes. * * [[thrown-exceptions]] * === Exceptions * There are three categories of exceptions that may be thrown: * * `ElasticsearchClientException`:: These are known exceptions, either an exception that occurred in the request pipeline * (such as max retries or timeout reached, bad authentication, etc...) or Elasticsearch itself returned an error (could * not parse the request, bad query, missing field, etc...). If it is an Elasticsearch error, the `ServerError` property * on the response will contain the the actual error that was returned. The inner exception will always contain the * root causing exception. * * `UnexpectedElasticsearchClientException`:: These are unknown exceptions, for instance a response from Elasticsearch not * properly deserialized. These are usually bugs and {github}/issues[should be reported]. This exception also inherits from `ElasticsearchClientException` * so an additional catch block isn't necessary, but can be helpful in distinguishing between the two. * * Development time exceptions:: These are CLR exceptions like `ArgumentException`, `ArgumentOutOfRangeException`, etc. * that are thrown when an API in the client is misused. * These should not be handled as you want to know about them during development. * */ }