Esempio n. 1
0
        /**
         * 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
                     .ConnectionStatusHandler(s => { })

                     /**
                      * Allows you to pass a `Action&lt;IElasticsearchResponse&gt;` that can eaves drop every time a response (good or bad) is created. If you have complex logging needs
                      * this is a good place to add that in.
                      */

                     .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 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
				.ConnectionStatusHandler(s => { })
				/** 
				* Allows you to pass a `Action&lt;IElasticsearchResponse&gt;` that can eaves drop every time a response (good or bad) is created. If you have complex logging needs 
				* this is a good place to add that in.
				*/

				.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.
			*/
		}