Viewing search results using NEST

Hi!
Im having a bit trouble getting the actual results (or JSON).
I know that the query works by the .total number of results..
To view the results im trying to use:

results = searchResponse.Documents;
        Console.WriteLine(results);

as shown in NEST guide
but when it runs it shows:
System.Collections.Generic.List`1[SearchPage.Person]

what should i do to view the actual results of the search?

anyone?

Would you mind linking to where it shows using Console.WriteLine in the docs to write out the documents?

When you say actual results, what do you mean? searchResponse.Documents will contain the a collection of C# POCOs of type T as given on the Search<T>() request, hydrated from the deserialization of the hits _source from the JSON response.

If you're looking to get the JSON response that comes back (for logging or debugging purposes?), the easiest way is probably using .DisableDirectStreaming() in conjunction with .PrettyJson() on ConnectionSettings, and passing a delegate to .OnRequestCompleted() to write out the response

var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var connectionSettings = new ConnectionSettings(pool)
    .PrettyJson()
    .DisableDirectStreaming()
    .OnRequestCompleted(apiCall =>
        {
            // do something with the request and response. Here I'm just logging
            // out to the Console, but you may be writing to file, writing to trace, etc.
            if (apiCall.RequestBodyInBytes != null)
            {
                Console.WriteLine(
                    $"{apiCall.HttpMethod} {apiCall.Uri} \n" +
                    $"{Encoding.UTF8.GetString(apiCall.RequestBodyInBytes)}");
            }
            else
            {
                Console.WriteLine($"{apiCall.HttpMethod} {apiCall.Uri}");
            }

            Console.WriteLine();

            if (apiCall.ResponseBodyInBytes != null)
            {
                Console.WriteLine($"Status: {apiCall.HttpStatusCode}\n" +
                         $"{Encoding.UTF8.GetString(apiCall.ResponseBodyInBytes)}\n" +
                         $"{new string('-', 30)}\n");
            }
            else
            {
                Console.WriteLine($"Status: {apiCall.HttpStatusCode}\n" +
                         $"{new string('-', 30)}\n");
            }
        });

var client = new ElasticClient(connectionSettings);

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