Serialize query from Nest client ElasticSearch 6.4

1.4k views Asked by At

Till ElasticSearch 6.0 we were able to serialize the search request (object of SearchRequest) to a string

        using (System.IO.MemoryStream mStream = new System.IO.MemoryStream())
        {
            ElasticClient.Serializer.Serialize(searchRequest, mStream);
            string rawQueryText = Encoding.ASCII.GetString(mStream.ToArray());
        }

Example is here too serialize query from Nest client elastic search 2.3

But in 6.4 version that has been removed and I am not able to locate exactly where is the documentation to serialize the query with 6.4 version https://github.com/elastic/elasticsearch-net

Can some one help me here?

1

There are 1 answers

0
Russ Cam On

You can use the extension method in ElasticsearchSerializerExtensions in Elasticsearch.Net

using Elasticsearch.Net;
using Nest;

var client = new ElasticClient();

var searchRequest = new SearchRequest
{
    Query = new MatchAllQuery()
};

var json = client.RequestResponseSerializer.SerializeToString(searchRequest);