|
| 1 | +[[configuration]] |
| 2 | +== Configuration |
| 3 | + |
| 4 | +Connecting to {es} with the client is easy, but it's possible that you'd like to |
| 5 | +change the default connection behaviour. There are a number of configuration |
| 6 | +options available on `ElasticsearchClientSettings` that can be used to control how the |
| 7 | +client interact with {es}. |
| 8 | + |
| 9 | +=== Options on ElasticsearchClientSettings |
| 10 | + |
| 11 | +The following is a list of available connection configuration options on |
| 12 | +`ElasticsearchClientSettings`: |
| 13 | + |
| 14 | +`Authentication`:: |
| 15 | + |
| 16 | +An implementation of `IAuthenticationHeader` describing what http header to use |
| 17 | +to authenticate with the product. |
| 18 | ++ |
| 19 | + `BasicAuthentication` for basic authentication |
| 20 | ++ |
| 21 | + `ApiKey` for simple secret token |
| 22 | ++ |
| 23 | + `Base64ApiKey` for Elastic Cloud style encoded api keys |
| 24 | + |
| 25 | +`ClientCertificate`:: |
| 26 | + |
| 27 | +Use the following certificates to authenticate all HTTP requests. You can also |
| 28 | +set them on individual request using `ClientCertificates`. |
| 29 | + |
| 30 | +`ClientCertificates`:: |
| 31 | + |
| 32 | +Use the following certificates to authenticate all HTTP requests. You can also |
| 33 | +set them on individual request using `ClientCertificates`. |
| 34 | + |
| 35 | +`ConnectionLimit`:: |
| 36 | + |
| 37 | +Limits the number of concurrent connections that can be opened to an endpoint. |
| 38 | +Defaults to 80 (see `DefaultConnectionLimit`). |
| 39 | ++ |
| 40 | +For Desktop CLR, this setting applies to the `DefaultConnectionLimit` property |
| 41 | +on the `ServicePointManager` object when creating `ServicePoint` objects, |
| 42 | +affecting the default `IConnection` implementation. |
| 43 | ++ |
| 44 | +For Core CLR, this setting applies to the `MaxConnectionsPerServer` property on |
| 45 | +the `HttpClientHandler` instances used by the `HttpClient` inside the default |
| 46 | +`IConnection` implementation. |
| 47 | + |
| 48 | +`DeadTimeout`:: |
| 49 | + |
| 50 | +The time to put dead nodes out of rotation (this will be multiplied by the |
| 51 | +number of times they've been dead). |
| 52 | + |
| 53 | +`DefaultDisableIdInference`:: |
| 54 | + |
| 55 | +Disables automatic Id inference for given CLR types. |
| 56 | ++ |
| 57 | +The client by default will use the value of a property named `Id` on a CLR type |
| 58 | +as the `_id` to send to {es}. Adding a type will disable this behaviour for that |
| 59 | +CLR type. If `Id` inference should be disabled for all CLR types, use |
| 60 | +`DefaultDisableIdInference`. |
| 61 | + |
| 62 | +`DefaultFieldNameInferrer`:: |
| 63 | + |
| 64 | +Specifies how field names are inferred from CLR property names. |
| 65 | ++ |
| 66 | +By default, the client camel cases property names. For example, CLR property |
| 67 | +`EmailAddress` will be inferred as "emailAddress" {es} document field name. |
| 68 | + |
| 69 | +`DefaultIndex`:: |
| 70 | + |
| 71 | +The default index to use for a request when no index has been explicitly |
| 72 | +specified and no default indices are specified for the given CLR type specified |
| 73 | +for the request. |
| 74 | + |
| 75 | +`DefaultMappingFor`:: |
| 76 | + |
| 77 | +Specify how the mapping is inferred for a given CLR type. The mapping can infer |
| 78 | +the index, id and relation name for a given CLR type, as well as control |
| 79 | +serialization behaviour for CLR properties. |
| 80 | + |
| 81 | +`DisableAutomaticProxyDetection`:: |
| 82 | + |
| 83 | +Disabled proxy detection on the webrequest, in some cases this may speed up the |
| 84 | +first connection your appdomain makes, in other cases it will actually increase |
| 85 | +the time for the first connection. No silver bullet! Use with care! |
| 86 | + |
| 87 | +`DisableDirectStreaming`:: |
| 88 | + |
| 89 | +When set to true will disable (de)serializing directly to the request and |
| 90 | +response stream and return a byte[] copy of the raw request and response. |
| 91 | +Defaults to false. |
| 92 | + |
| 93 | +`DisablePing`:: |
| 94 | + |
| 95 | +This signals that we do not want to send initial pings to unknown/previously |
| 96 | +dead nodes and just send the call straightaway. |
| 97 | + |
| 98 | +`DnsRefreshTimeout`:: |
| 99 | + |
| 100 | +DnsRefreshTimeout for the connections. Defaults to 5 minutes. |
| 101 | + |
| 102 | +`EnableDebugMode`:: |
| 103 | + |
| 104 | +Turns on settings that aid in debugging like `DisableDirectStreaming()` and |
| 105 | +`PrettyJson()` so that the original request and response JSON can be inspected. |
| 106 | +It also always asks the server for the full stack trace on errors. |
| 107 | + |
| 108 | +`EnableHttpCompression`:: |
| 109 | + |
| 110 | +Enable gzip compressed requests and responses. |
| 111 | + |
| 112 | +`EnableHttpPipelining`:: |
| 113 | + |
| 114 | +Whether HTTP pipelining is enabled. The default is `true`. |
| 115 | + |
| 116 | +`EnableTcpKeepAlive`:: |
| 117 | + |
| 118 | +Sets the keep-alive option on a TCP connection. |
| 119 | ++ |
| 120 | +For Desktop CLR, sets `ServicePointManager`.`SetTcpKeepAlive`. |
| 121 | + |
| 122 | +`EnableTcpStats`:: |
| 123 | + |
| 124 | +Enable statistics about TCP connections to be collected when making a request. |
| 125 | + |
| 126 | +`GlobalHeaders`:: |
| 127 | + |
| 128 | +Try to send these headers for every request. |
| 129 | + |
| 130 | +`GlobalQueryStringParameters`:: |
| 131 | + |
| 132 | +Append these query string parameters automatically to every request. |
| 133 | + |
| 134 | +`MaxDeadTimeout`:: |
| 135 | + |
| 136 | +The maximum amount of time a node is allowed to marked dead. |
| 137 | + |
| 138 | +`MaximumRetries`:: |
| 139 | + |
| 140 | +When a retryable exception occurs or status code is returned this controls the |
| 141 | +maximum amount of times we should retry the call to {es}. |
| 142 | + |
| 143 | +`MaxRetryTimeout`:: |
| 144 | + |
| 145 | +Limits the total runtime including retries separately from `RequestTimeout`. |
| 146 | +When not specified defaults to `RequestTimeout` which itself defaults to 60 |
| 147 | +seconds. |
| 148 | + |
| 149 | +`MemoryStreamFactory`:: |
| 150 | + |
| 151 | +Provides a memory stream factory. |
| 152 | + |
| 153 | +`NodePredicate`:: |
| 154 | + |
| 155 | +Register a predicate to select which nodes that you want to execute API calls |
| 156 | +on. Note that sniffing requests omit this predicate and always execute on all |
| 157 | +nodes. When using an `IConnectionPool` implementation that supports reseeding of |
| 158 | +nodes, this will default to omitting master only node from regular API calls. |
| 159 | +When using static or single node connection pooling it is assumed the list of |
| 160 | +node you instantiate the client with should be taken verbatim. |
| 161 | + |
| 162 | +`OnRequestCompleted`:: |
| 163 | + |
| 164 | +Allows you to register a callback every time a an API call is returned. |
| 165 | + |
| 166 | +`OnRequestDataCreated`:: |
| 167 | + |
| 168 | +An action to run when the `RequestData` for a request has been created. |
| 169 | + |
| 170 | +`PingTimeout`:: |
| 171 | + |
| 172 | +The timeout in milliseconds to use for ping requests, which are issued to |
| 173 | +determine whether a node is alive. |
| 174 | + |
| 175 | +`PrettyJson`:: |
| 176 | + |
| 177 | +Provide hints to serializer and products to produce pretty, non minified json. |
| 178 | ++ |
| 179 | +Note: this is not a guarantee you will always get prettified json. |
| 180 | + |
| 181 | +`Proxy`:: |
| 182 | + |
| 183 | +If your connection has to go through proxy, use this method to specify the |
| 184 | +proxy url. |
| 185 | + |
| 186 | +`RequestTimeout`:: |
| 187 | + |
| 188 | +The timeout in milliseconds for each request to {es}. |
| 189 | + |
| 190 | +`ServerCertificateValidationCallback`:: |
| 191 | + |
| 192 | +Register a `ServerCertificateValidationCallback` per request. |
| 193 | + |
| 194 | +`SkipDeserializationForStatusCodes`:: |
| 195 | + |
| 196 | +Configure the client to skip deserialization of certain status codes, for |
| 197 | +example, you run {es} behind a proxy that returns an unexpected json format. |
| 198 | + |
| 199 | +`SniffLifeSpan`:: |
| 200 | + |
| 201 | +Force a new sniff for the cluster when the cluster state information is older |
| 202 | +than the specified timespan. |
| 203 | + |
| 204 | +`SniffOnConnectionFault`:: |
| 205 | + |
| 206 | +Force a new sniff for the cluster state every time a connection dies. |
| 207 | + |
| 208 | +`SniffOnStartup`:: |
| 209 | + |
| 210 | +Sniff the cluster state immediately on startup. |
| 211 | + |
| 212 | +`ThrowExceptions`:: |
| 213 | + |
| 214 | +Instead of following a c/go like error checking on response. `IsValid` do throw |
| 215 | +an exception (except when `SuccessOrKnownError` is false) on the client when a |
| 216 | +call resulted in an exception on either the client or the {es} server. |
| 217 | ++ |
| 218 | +Reasons for such exceptions could be search parser errors, index missing |
| 219 | +exceptions, and so on. |
| 220 | + |
| 221 | +`TransferEncodingChunked`:: |
| 222 | + |
| 223 | +Whether the request should be sent with chunked Transfer-Encoding. |
| 224 | + |
| 225 | +`UserAgent`:: |
| 226 | + |
| 227 | +The user agent string to send with requests. Useful for debugging purposes to |
| 228 | +understand client and framework versions that initiate requests to {es}. |
| 229 | + |
| 230 | + |
| 231 | +==== ElasticsearchClientSettings with ElasticsearchClient |
| 232 | + |
| 233 | +Here's an example to demonstrate setting configuration options using the client. |
| 234 | + |
| 235 | +[source,csharp] |
| 236 | +---- |
| 237 | +var settings= new ElasticsearchClientSettings() |
| 238 | + .DefaultMappingFor<Project>(i => i |
| 239 | + .IndexName("my-projects") |
| 240 | + .IdProperty(p => p.Name) |
| 241 | + ) |
| 242 | + .EnableDebugMode() |
| 243 | + .PrettyJson() |
| 244 | + .RequestTimeout(TimeSpan.FromMinutes(2)); |
| 245 | +
|
| 246 | +var client = new ElasticsearchClient(settings); |
| 247 | +---- |
0 commit comments