{"id":814,"date":"2021-08-23T08:10:58","date_gmt":"2021-08-23T08:10:58","guid":{"rendered":"https:\/\/bruceng.com\/dev\/?p=814"},"modified":"2021-08-23T08:10:58","modified_gmt":"2021-08-23T08:10:58","slug":"how-to-get-raw-query-generated-by-elasticsearch-nest-library-for-debugging-purpose","status":"publish","type":"post","link":"https:\/\/bruceng.com\/dev\/?p=814","title":{"rendered":"How to get raw query generated by Elasticsearch NEST library for debugging purpose"},"content":{"rendered":"\n<p>Source: <a href=\"https:\/\/stackoverflow.com\/questions\/28939022\/get-raw-query-from-nest-client\/50023531#50023531\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/stackoverflow.com\/questions\/28939022\/get-raw-query-from-nest-client\/50023531#50023531<\/a><\/p>\n\n\n\n<p>For NEST \/ Elasticsearch.NET v6.0.2, use the ApiCall property of the IResponse object. You can write a handy extension method like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static string ToJson(this IResponse response)\n{\n    return Encoding.UTF8.GetString(response.ApiCall.RequestBodyInBytes);\n}\n<\/code><\/pre>\n\n\n\n<p>Or, if you want to log all requests made to Elastic, you can intercept responses with the connection object:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var node = new Uri(\"https:\/\/localhost:9200\");\nvar pool = new SingleNodeConnectionPool(node);\nvar connectionSettings = new ConnectionSettings(pool, new HttpConnection());\nconnectionSettings.OnRequestCompleted(call =&gt;\n{\n    Debug.Write(Encoding.UTF8.GetString(call.RequestBodyInBytes));\n});<\/code><\/pre>\n\n\n\n<p>You need to call on the ES client connection setting object to allow reading request JSON. This is best done on DEBUG mode.<\/p>\n\n\n\n<p>connectionSettings.DisableDirectStreaming(true)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/stackoverflow.com\/questions\/28939022\/get-raw-query-from-nest-client\/50023531#50023531 For NEST \/ Elasticsearch.NET v6.0.2, use the ApiCall property of the IResponse object. You can write a handy extension method like this: Or, if you want to log all requests made to Elastic, you can intercept responses with the connection object: You need to call on the ES client connection setting object to &hellip; <a href=\"https:\/\/bruceng.com\/dev\/?p=814\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to get raw query generated by Elasticsearch NEST library for debugging purpose&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[17,117,116],"class_list":["post-814","post","type-post","status-publish","format-standard","hentry","category-tips-and-tricks","tag-debug","tag-elastic-stack","tag-elasticsearch"],"_links":{"self":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/814","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=814"}],"version-history":[{"count":1,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/814\/revisions"}],"predecessor-version":[{"id":815,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/814\/revisions\/815"}],"wp:attachment":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}