序列化来自Nest客户端ElasticSearch 6.4的查询

时间:2018-11-04 15:52:06

标签: elasticsearch elasticsearch.net

直到ElasticSearch 6.0,我们才能够将搜索请求(SearchRequest的对象)序列化为字符串

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

示例也在这里serialize query from Nest client elastic search 2.3

但是在已删除的6.4版本中,我无法准确找到将6.4版本的查询序列化的文档的位置 https://github.com/elastic/elasticsearch-net

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

您可以在Elasticsearch.Net的ElasticsearchSerializerExtensions中使用扩展方法

using Elasticsearch.Net;
using Nest;

var client = new ElasticClient();

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

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