# Viewing search results using NEST

**URL:** <https://discuss.elastic.co/t/viewing-search-results-using-nest/108724>\
**Category:** Elasticsearch\
**Created:** [November 22, 2017, 1:55pm UTC](https://discuss.elastic.co/t/viewing-search-results-using-nest/108724 "2017-11-22T13:55:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liron1379](https://avatars.discourse-cdn.com/v4/letter/l/dec6dc/32.png) [@Liron1379](https://discuss.elastic.co/u/Liron1379)\
**Post date:** [November 22, 2017, 1:55pm UTC](https://discuss.elastic.co/t/viewing-search-results-using-nest/108724/1 "2017-11-22T13:55:52Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Liron1379](https://avatars.discourse-cdn.com/v4/letter/l/dec6dc/32.png) [@Liron1379](https://discuss.elastic.co/u/Liron1379)\
**Post date:** [November 23, 2017, 5:18am UTC](https://discuss.elastic.co/t/viewing-search-results-using-nest/108724/2 "2017-11-23T05:18:20Z")

</div>

anyone?

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [November 23, 2017, 8:19pm UTC](https://discuss.elastic.co/t/viewing-search-results-using-nest/108724/3 "2017-11-23T20:19:30Z")

</div>

> [@Liron1379](#):
>
> ```auto
> results = searchResponse.Documents;
> Console.WriteLine(results);
> 
> ```
> 
> as shown in NEST guide

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](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/logging-with-on-request-completed.html)

```auto
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);

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 21, 2017, 8:20pm UTC](https://discuss.elastic.co/t/viewing-search-results-using-nest/108724/4 "2017-12-21T20:20:02Z")

</div>

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