Serialize a request with Nest 2.3 Flexible Search Client

Since updating my Nest client to version 2.2.1, I canโ€™t see the request that I send to my elastic search client (now version 2.3.0). I used this line:

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

But this method now returns void instead of the used JSON. ConnectionStatus also does not exist, so I can no longer see the json I'm sending, does anyone know about this? CallDetails.RequestBodyInBytes is available, but returns null.

+5
source share
2 answers

Take a look at the documentation for NEST 2.x on the connection . CallDetails.RequestBodyInBytes will be null if you do not set .DisableDirectStreaming() on ConnectionSettings , which is passed to the ElasticClient constructor

 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 displayed in the CallDetails response

 var response = client.Search<Document>(); var requestJson = Encoding.UTF8.GetString(response.CallDetails.RequestBodyInBytes); var responseJson = Encoding.UTF8.GetString(response.CallDetails.ResponseBodyInBytes); 

Although development may be useful for exiting all requests and responses .

+5
source

Now, the Serialize method requires a stream on which it will write the original json request. - Work correctly for Nest 5.3.0:

  var stream = new System.IO.MemoryStream(); nestClient.Serializer.Serialize(query, stream); var jsonQuery = System.Text.Encoding.UTF8.GetString(stream.ToArray()); 
0
source

Source: https://habr.com/ru/post/1246879/


All Articles