【问题标题】:Elastic search: How extract total count from elastic multi search query response IMultiSearchResponse弹性搜索:如何从弹性多搜索查询响应 IMultiSearchResponse 中提取总数
【发布时间】:2017-01-26 17:15:42
【问题描述】:

我有弹性多搜索查询,它返回 3 个文档列表。

有意义的响应看起来像:

{
   "responses": [
      {
         ...
         "hits": {
            "total": 0,
            "max_score": null,
            "hits": []
         }
      },
      {
         ...
         "hits": {
            "total": 0,
            "max_score": null,
            "hits": []
         }
      },
      {
         ...
         "hits": {
            "total": 0,
            "max_score": null,
            "hits": []
         }
      }
   ]
}

我通过“results.GetResponses()”获得了 c# 中的 3 个文档列表。

但我不知道如何获得每个列表的总数?即总数?

【问题讨论】:

  • 我猜,你应该手动合并你的回复。

标签: c# elasticsearch nest


【解决方案1】:

您可以汇总所有响应 total 属性:

response.GetResponses<object>().Sum(r=>r.HitsMetaData.Total);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-09
    • 1970-01-01
    • 1970-01-01
    • 2017-12-02
    相关资源
    最近更新 更多