1

I'm working on an application that uses the Elasticsearch .NET client libraries (Elasticsearch.Net and NEST) and, as part of a conversion from Elasticsearch 1.x to 2.x, I'm trying to work out the 2.x equivalents of some data that was previously exposed via IElasticSearchResponse.

In our 1.x implementation, we carried out the following logic inside a method that was supplied to ConnectionSettings.SetConnectionStatusHandler():

    private static void LogElasticSearch1DotXMetrics(IElasticsearchResponse resp)
    {
        if (resp.NumberOfRetries > 0)
            PerformSomeLoggingOperationOn(resp.NumberOfRetries);
    }

In 2.x, I believe that the equivalent to ConnectionSettings.SetConnectionStatusHandler() is to pass a method to ConnectionSettings.OnRequestCompleted(). This method will receive an IApiCallDetails instance.

    private static void LogElasticSearch2DotXMetrics(IApiCallDetails details)
    {
        PerformSomeLoggingOperationOn(details.??????);
    }

I haven't been able to find an obvious equivalent for IElasticSearchResponse.NumberOfRetries on IApiCallDetails. Can anyone point me in the right direction?

Ivan Karajas
  • 1,081
  • 8
  • 14

1 Answers1

0

I've put this question to Elasticsearch support and am summarising their response here in case anyone else finds it useful.

There is no direct equivalent to NumberOfRetries in Elasticsearch.NET 2.x. However, there is an event for the case when the maximum number of retries is reached.

var maxRetriesReached = callDetails.AuditTrail
    .Any(a => a.Event == AuditEvent.MaxRetriesReached);

Alternatively if you're really interested in the number of retries, rather than whether or not a query was abandoned, you could also observe the audit trail for BadResponse events.

var badResponses = callDetails.AuditTrail
    .Any(a => a.Event == AuditEvent.BadResponse);
Ivan Karajas
  • 1,081
  • 8
  • 14