Returning Raw Json in ElasticSearch NEST query

落爺英雄遲暮 提交于 2019-11-30 20:21:07

Hi Pedro you can do this with NEST

var searchDescriptor = new SearchDescriptor<ElasticSearchProject>()
    .Query(q=>q.MatchAll());
var request = this._client.Serializer.Serialize(searchDescriptor);
ConnectionStatus result = this._client.Raw.SearchPost(request);
Assert.NotNull(result);
Assert.True(result.Success);
Assert.IsNotEmpty(result.Result);

This allows you to strongly type your queries, but return the string .Result which is the raw response from elasticsearch as string to your

request can be an object or the string so if you are OK with the internal json serialize just pass searchDescriptor directly

Use RequestResponseSerializer instead of Serializer.

var searchDescriptor = ...;
...
byte[] b = new byte[60000];
using (MemoryStream ms = new MemoryStream(b))
{
    this._client.RequestResponseSerializer.Serialize(searchDescriptor , ms);
}
var rawJson = System.Text.Encoding.Default.GetString(b);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!