9
votes

I'm doing a small research about a client for elastic search in .net and I found that NEST is one of the most supported solutions for this matter.

I was looking at Nest's docummentation and I couldn´t find a way to output a raw json from a query and avoid the serialization into an object, because I'm using angularJs in the front end I don´t want to overload the process of sending the information to the client with some unnecessary steps.

......and also I'd like to know how can I overrdide the serialization process?

I found that NEST uses Json.NET which I would like to change for the servicestack json serielizer.

thanks!

2

2 Answers

12
votes

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

0
votes

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);