【问题标题】:How to perform Sub Aggregation using NEST?如何使用 NEST 执行子聚合?
【发布时间】:2020-04-21 13:22:33
【问题描述】:

我正在尝试使用存储桶聚合按特定标准执行分组文档,并为每个存储桶执行总和聚合。

下面是我的尝试

ISearchResponse<PaymentReportModel> paymentSearchResponse =
                ConnectionToES.EsClient()
                .Search<PaymentReportModel>
                (s => s
                    .Index("payments")                    
                    .Query(q => q.MatchAll() )

                     .Aggregations(a => a

                     .Terms("paymentstatus_types", ts => ts
                        .Field(o => o.paymentstatus)
                            .Aggregations(aa => aa
                                .Sum("sumreceiptamount", sa => sa
                                    .Field(o => o.totalreceiptamount)
                                    )
                                )
                            )
                        )
                    );

var paymentRecords = paymentSearchResponse.Documents ; // Count = 0

付款索引中有 356 个文档,因此计数为零(0)。

我的 DTO 如下

public class PaymentReportModel
{
    public string paymentid { get; set; }
    public float? totalreceiptamount { get; set; }        
    public string paymentstatus { get; set; }       
}

等效的 DSL 产生

"aggregations" : {
    "paymentstatus_types" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "ReceivedByCollector",
          "doc_count" : 36,
          "sumreceiptamount" : {
            "value" : 56914.14031982422
          }
        },
        {
          "key" : "CollectionAcknowledged",
          "doc_count" : 17,
          "sumreceiptamount" : {
            "value" : 6802.75
          }
        },
        {
          "key" : "PayInSlipCreated",
          "doc_count" : 10,
          "sumreceiptamount" : {
            "value" : 4183.0
          }
        },
        {
          "key" : "CollectionSuccess",
          "doc_count" : 5,
          "sumreceiptamount" : {
            "value" : 27.0
          }
        }
      ]
    }
  }
}

我犯了什么错误?

【问题讨论】:

  • 一定会帮助你的,我正忙于我的任务,今晚我会检查一下,我会在明天早上通知你

标签: c# elasticsearch nest dsl


【解决方案1】:

因此,根据您的查询,您将不会获得文档,因为您正在使用聚合。可以肯定的是,如果您想要文档,则删除 size:0。然后您将获得聚合结果以及大小为 10 的文档。

【讨论】:

  • 意思,我不明白。我在哪里使用尺寸(0)?如果我在任何地方断开连接,请告诉我
  • 你能从上面提到的查询中得到文件吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多