当前位置: 首页>>代码示例>>C#>>正文


C# ConnectionConfiguration.GlobalQueryStringParameters方法代码示例

本文整理汇总了C#中ConnectionConfiguration.GlobalQueryStringParameters方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionConfiguration.GlobalQueryStringParameters方法的具体用法?C# ConnectionConfiguration.GlobalQueryStringParameters怎么用?C# ConnectionConfiguration.GlobalQueryStringParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConnectionConfiguration的用法示例。


在下文中一共展示了ConnectionConfiguration.GlobalQueryStringParameters方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AvailableOptions

		/**
		 * 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://username:[email protected]:9200");
			var settings = new ConnectionConfiguration(uri);

			/**
			*  ...but may become tedious when using connection pooling with multiple nodes.
			*/
		}
开发者ID:matteus6007,项目名称:elasticsearch-net,代码行数:96,代码来源:Connecting.doc.cs

示例2: AvailableOptions

		/**
		 * 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://username:[email protected]: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.
			*
			*/
		}
开发者ID:RossLieberman,项目名称:NEST,代码行数:64,代码来源:Connecting.doc.cs


注:本文中的ConnectionConfiguration.GlobalQueryStringParameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。