【问题标题】:Return elastic search result as raw JSON将弹性搜索结果作为原始 JSON 返回
【发布时间】:2017-03-01 05:47:27
【问题描述】:

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

【问题讨论】:

    标签: serialization elasticsearch json.net nest


    【解决方案1】:

    在低级客户端上传递给.Search&lt;T&gt; 的类型T 指定了结果的返回类型。为了返回 json,您只需将其更改为 string

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-10
      • 1970-01-01
      • 1970-01-01
      • 2016-12-09
      • 2012-03-06
      • 2018-04-13
      • 1970-01-01
      • 2019-07-20
      相关资源
      最近更新 更多