Get raw query from NEST client

前端 未结 8 799
太阳男子
太阳男子 2021-01-30 08:33

Is it possible to get the raw search query from the NEST client?

var result = client.Search(s => s
             


        
8条回答
  •  独厮守ぢ
    2021-01-30 08:58

    For NEST / Elasticsearch.NET v6.0.2, use the ApiCall property of the IResponse object. You can write a handy extension method like this:

    public static string ToJson(this IResponse response)
    {
        return Encoding.UTF8.GetString(response.ApiCall.RequestBodyInBytes);
    }
    

    Or, if you want to log all requests made to Elastic, you can intercept responses with the connection object:

    var node = new Uri("https://localhost:9200");
    var pool = new SingleNodeConnectionPool(node);
    var connectionSettings = new ConnectionSettings(pool, new HttpConnection());
    connectionSettings.OnRequestCompleted(call =>
    {
        Debug.Write(Encoding.UTF8.GetString(call.RequestBodyInBytes));
    });
    

提交回复
热议问题