在ElasticSearch NEST查询中返回Raw Json [英] Returning Raw Json in ElasticSearch NEST query

查看:279
本文介绍了在ElasticSearch NEST查询中返回Raw Json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个有关客户端关于.net的弹性搜索的小型研究,我发现NEST是这个问题最受支持的解决方案之一。



我正在查看Nest的文档,我找不到从查询中输出一个raw json的方法,并避免序列化成一个对象,因为我在前端使用angularJs我不想重载过程发送信息给客户端一些不必要的步骤。



......我也想知道如何超越序列化过程? p>

我发现NEST使用Joss.NET,我想为servicestack json serielizer更改。



谢谢!

解决方案

您好佩德罗您可以使用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);

这允许您强烈键入查询,但返回字符串 .Result 这是从弹性搜索的原始响应作为字符串到您的



请求可以是对象或字符串,所以如果你可以使用内部的json serialize只是传递searchDescriptor直接


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!

解决方案

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

这篇关于在ElasticSearch NEST查询中返回Raw Json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆