How to get in C# client not-null response even for failed search requests?

Hi there!

There is C# code that generates searches through code like that:
searchResult = client.Search(descriptor);

The request generated contains inappropriate data, and therefore I get Elasticsearch.Net.ElasticsearchClientException, and it's completely OK. When I turn on DisableDirectStreaming, I can see the json that ElasticsearchCluster returns and the root_cause in my apiCallDetails:
"reason" : "[simple_query_string] analyzer [custom_search_analyzer] not found",

The problem is that I can not turn on DisableDirectStreaming due to perfomance cost and that searchResult is null, though the documentation on ElasticsearchClientException Exceptions | Elasticsearch.Net and NEST: the .NET clients [6.x] | Elastic states that the response should contain ServerError with the root cause.

What am I doing wrong here? How can I tune the code or the elasticsearch cluster to get from client.Search not-null response with ServerError and the root cause?

Hi @Leonid_P,

Welcome back! I've moved your question to the language-clients tag as I think it's more appropriate.

Can you share the code snippet?

Hi Carly, thank you for changing the tag, it's got really more correct, here are my sting of code and some additional explainaition:

// Client generation
var settings = new ConnectionSettings(connectionPool)
				.DisableDirectStreaming(false)
				.ThrowExceptions(true)
				.// and some more settings which are not importaint here

return new ElasticClient(settings);

and

// The search that I need to deal with:
var searchResult = await ReadClient?.SearchAsync(descriptor);

My goal is to get the root_cause for failed searchesfor example
"reason" : "[simple_query_string] analyzer [custom_search_analyzer] not found",

How can I do it?

I would like neither setting DisableDirectStreaming(true) (due to performance reasons), nor 'ThrowExceptions(true)` (because for most searches with the same client we do need the exception).

So the desirable code is something like this:

var searchResult = await ReadClient?.SearchAsync(descriptor.MyTrickyWayToGetNotNullResponseEvenForFailedRequestsThoughThrowExceptionsIsSwitchedOn());

or some tricky way to get the root cause in .OnRequestCompleted() though DisableDirectStreaming is set to false.

Is it possible without creating different slients wit different ThrowExceptions behaviour?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.