Nest 2, What happened to ExposeRawResponse and ConnectionStatus?

Prior to 2.0 it was possible to set ExposeRawResponse on the ConnectionSettings to keep a copy of the raw response on the result object for debugging. In addition, on the result object you could inspect ConnectionSettings to see the response.

Both of these methods are missing now and there's nothing in the documentation.

ExposeRawResponse is now DisableDirectStreaming.

The documentation for NEST 2.x on Connecting provides an example of configuring inspection of all requests and responses using OnRequestCompleted

var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));

var settings = new ConnectionSettings(connectionPool, new InMemoryConnection()) 
    .DefaultIndex("default-index")
    .DisableDirectStreaming()
    .OnRequestCompleted(response =>
    {
        // log out the request and the request body, if one exists for the type of request
        if (response.RequestBodyInBytes != null)
        {
            Console.WriteLine(
                $"{response.HttpMethod} {response.Uri} \n" +
                $"{Encoding.UTF8.GetString(response.RequestBodyInBytes)}");
        }
        else
        {
            Console.WriteLine($"{response.HttpMethod} {response.Uri}");
        }

        // log out the response and the response body, if one exists for the type of response
        if (response.ResponseBodyInBytes != null)
        {
            Console.WriteLine($"Status: {response.HttpStatusCode}\n" +
                     $"{Encoding.UTF8.GetString(response.ResponseBodyInBytes)}\n" +
                     $"{new string('-', 30)}\n");
        }
        else
        {
            Console.WriteLine($"Status: {response.HttpStatusCode}\n" +
                     $"{new string('-', 30)}\n");
        }
    });

var client = new ElasticClient(settings);

If you just want to inspect the response ad-hoc, then set DisableDirectStreaming and then get the string from the response body bytes

Encoding.UTF8.GetString(response.ResponseBodyInBytes)
1 Like

Awesome, thank you. And thanks for the documentation link. I was still using the old one at http://nest.azurewebsites.net/