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:
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);
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.