Skip to content

Instantly share code, notes, and snippets.

@ddieppa
Last active September 26, 2022 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddieppa/2a12fe060db6a862a4068abef19d1a49 to your computer and use it in GitHub Desktop.
Save ddieppa/2a12fe060db6a862a4068abef19d1a49 to your computer and use it in GitHub Desktop.
Get Final query from Elasticsearch Nest client

Get final query from Elasticsearch Nest client

First you have to set this flag

var settings = new ConnectionSettings(connectionPool)
    .DisableDirectStreaming();

📓This is for Nest client 6.X: Debug Information in 6.x the default is true

/// <summary>
/// Ensures the response bytes are always available on the <see cref="T:Elasticsearch.Net.ElasticsearchResponse`1" /><para>
/// IMPORTANT: Depending on the registered serializer,
/// this may cause the response to be buffered in memory first, potentially affecting performance.
/// </para></summary>
public T DisableDirectStreaming(bool b = true) => this.Assign<bool>(b, (Action<ConnectionConfiguration<T>, bool>) ((a, v) => a._disableDirectStreaming = v));

But for the most current version 8.X this is a summary:

DisableDirectStreaming When set to true will disable (de)serializing directly to the request and response stream and return a byte[] copy of the raw request and response. Defaults to false.

If you have something like this:

var initialResponse = await _elasticClient.SearchAsync<TResult>
            (scr => scr
                .From(0)
                .Size(scrollSize)
                .Type(docTypeName)
                .Query(q => query)
                .Scroll(scrollTimeout));

in the immediate window (or similar tool) you can call this:

initialResponse.DebugInformation

Or

_elasticClient.RequestResponseSerializer.SerializeToString(query);
published: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment