将弹性搜索结果作为原始JSON返回

时间:2016-10-19 14:13:31

标签: serialization elasticsearch json.net nest

很抱歉重复的问题,但这似乎不适用于当前的Elastic Search 2.x版本。基本上,我使用NEST向ES发送查询,并希望以简单的JSON获得响应,就像在Sense上使用POST命令一样。此处存在类似问题:Returning Raw Json in ElasticSearch NEST query

使用以下方法检索结果:

var searchResult = _elasticClient.LowLevel.Search<SearchResponse<SearchResult>>(querytEST);

想要的结果:

{
  "took": 406,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "hits": {
    "total": 14,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "query": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 1,
      "buckets": [
        {
          "key": "laura",
          "doc_count": 14,
          "top": {
            "hits": {
              "total": 14,
              "max_score": 4.1078563,
              "hits": [
                {...

1 个答案:

答案 0 :(得分:1)

在低级客户端上传递给T的类型.Search<T>指定结果的返回类型。要返回json,只需将其更改为string

即可
var searchResult = _elasticClient.LowLevel.Search<string>(querytEST);
相关问题