Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

serialize query from Nest client elastic search 2.3

Since upgrading my Nest client to 2.2.1 I'm unable see the query I'm submitting to my elastic search client (now version 2.3.0). I used to use this line:

string searchJson = Encoding.UTF8.GetString(client.Serializer.Serialize(myQueryHere));  

But this method now returns void instead of the JSON it used to. ConnectionStatus also doesn't exist so I can no longer see the json i'm sending, does anyone know of a way? CallDetails.RequestBodyInBytes is available but that returns null.

like image 347
zappa Avatar asked Apr 11 '16 14:04

zappa


1 Answers

Take a look at the documentation for NEST 2.x on Connecting. CallDetails.RequestBodyInBytes will be null unless you set .DisableDirectStreaming() on ConnectionSettings that is passed to the constructor of ElasticClient

var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));  
var settings = new ConnectionSettings(connectionPool) 
    .DisableDirectStreaming();

var client = new ElasticClient(settings);

now a copy of the request and response bytes will be exposed on the response CallDetails

var response = client.Search<Document>();

var requestJson = Encoding.UTF8.GetString(response.CallDetails.RequestBodyInBytes);
var responseJson = Encoding.UTF8.GetString(response.CallDetails.ResponseBodyInBytes);

Whilst developing it may be useful to log out all requests and responses.

like image 85
Russ Cam Avatar answered Sep 29 '22 09:09

Russ Cam