WARNING: Version 5.x has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
ElasticsearchResponse<T> is the container return type for all API calls. It has the following properties:
- The call succeeded and was succesful (200 range). Note that even if you get a 200 back from Elasticsearch, in many cases it’s still recommended to check the actual response making sure it succeeded on enough shards.
- When a call succeeds but does not return a HTTP status code of 200 this property will have details on the error. Please see the section on error handling for more details.
- The HTTP status code that the call returned.
- Holds the exception that occurred on the Elasticsearch server. Null if no exception occurred.
The original exception from the Elasticsearch server mapped as an
ElasticsearchServerError, otherwise null.
- The HTTP method used for making the request (POST, GET, PUT, HEAD, DELETE).
- The URL the request was sent to.
byterequest that was sent to Elasticsearch.
byterepresentation of the response from Elasticsearch, only set when
ExposeRawResponses()is set. See the Connecting section.
Tobject representing the response.
Meta data returned on the response, if
EnableMetricsis set, otherwise null. See the Connecting section.
- The number of times the request was tried.
Typed API Callsedit
Elasticsearch.Net does not provide typed objects representing the responses. This is up to the developer to map.
var result = client.Search<MyType>()
In this example
MyType is a type you provide to deserialize Elasticsearch’s response to.
var myTypeInstance = client.Response
If you specify
byte the response will not go through the registered
ISerializer but simply read and returned.
var result = client.Search<string>(); var stringResponse = result.Response;
This can be handy if you want to inspect the json dynamically by passing it into
supports dynamic usecases out of the box.
Dynamic API Callsedit
If you do not provide an explicit
<T> for your return type
Elasticsearch.Net will deserialize into a
var result = client.Search(); int? myInt = result.Response .hits.hits.nestedObject["someOtherValue"].myInt;
This will try and read
hits.hits.nestedObject.someOtherValue.myInt from the search response and it won’t throw null binding exceptions
nestedObject does not exist in the second hit.
This is really great for exploratory programming but dynamic dispatch in C# is not the fastest part of the language. It’s highly recommended you try and map responses to an explicit object instead.
INFO: DynamicDictionary comes from the Nancyfx project but is slightly modified to support arbitrary call depths without null checks in between.