Return 原始弹性搜索结果 JSON

Return elastic search result as raw JSON

抱歉重复问题,但这似乎不适用于当前的 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": [
                {...

在低级别客户端上传递给 .Search<T> 的类型 T 指定了结果的 return 类型。为了获得 json returned,您只需将其更改为 string

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