如何在桶聚合中进行过滤器聚合?

2024-04-14

我有以下要求。我有一些如下所示的记录(作为示例)

agreementid = 1, lastdispositioncode = PTP , feedbackdate = 30/11/2020 
agreementid = 1, lastdispositioncode = PTP  , feedbackdate = 29/11/2020
agreementid = 1, lastdispositioncode = BPTP , feedbackdate = 21/11/2020
agreementid = 2, lastdispositioncode = BPTP  , feedbackdate = 29/11/2020
agreementid = 2, lastdispositioncode = BPTP , feedbackdate = 11/11/2020
agreementid = 3, lastdispositioncode = SBPTP  , feedbackdate = 24/11/2020

在这里,首先我们必须

  • 第一组协议id,
  • 然后对feedbackdate进行排序,得到最新的记录
  • 之后必须计算最后的处置代码的数量。

上面的数据将给出下面的结果

ptp = 1 (since latest record of PTP is on 30/11/2020 for AggrementID = 1)
bptp = 3 (since 

                for AggrementID = 1, latest record of BPTP is on 21/11/2020
                for AggrementID = 2, latest record of BPTP is on 29/11/2020
                for AggrementID = 3, latest record of SBPTP is on 24/11/2020)
            

我尝试了以下程序,但查询失败。

class Program
{
    static void Main(string[] args)
    {
        var ptpDispositionCodes = new TermsQuery
        {
            IsVerbatim = true,
            Field = "lastdispositioncode",
            Terms = new string[] { "PTP" },
        };

        var bptpDispositionCodes = new TermsQuery
        {
            IsVerbatim = true,
            Field = "lastdispositioncode",
            Terms = new string[] { "BPTP","SBPTP" },
        };
        
        ISearchResponse<TestReportModel> searchResponse =
            ConnectionToES.EsClient()
            .Search<TestReportModel>
            (s => s
                .Index("feedbackdata")
                .From(0)
                .Size(50000)
                .Query(q =>q.MatchAll())
                .Aggregations(a => a
                    .Terms("Agreement_ID", t => t
                        .Field(f => f.agreementid.Suffix("keyword"))
                        .Aggregations(aa => aa
                            .TopHits("latest_feedbackdate_sort", th => th.Sort(so => so.Descending(f => f.feedbackdate))
                            
                                .Size(1) //get the latest record 
                            )

                        )
                        .Aggregations(fa => fa

                            .Filter("ptp_aggs", f => f.Filter(fd => ptpDispositionCodes))
                            .Filter("bptp_aggs", f => f.Filter(fd => bptpDispositionCodes))                         
                        )
                    )
                )
            );
        
        var ptpDocCount = ((Nest.SingleBucketAggregate)trailSearchResponse.Aggregations["ptp_aggs"]).DocCount;
        var bptpDocCount = ((Nest.SingleBucketAggregate)trailSearchResponse.Aggregations["bptp_aggs"]).DocCount;
    }
}

DTO

public class TestReportModel
{
    public string agreementid { get; set; }
    public string trailstatus { get; set; }        
    public string lastdispositioncode { get; set; }        
}

public class TestOutputAPIModel
{
    public List<TestModel> TestModelDetail { get; set; }    
}

public class TestModel
{   
    public string TrailStatus { get; set; }
    public int NoOfAccounts { get; set; }
    
}

这是迄今为止我收到的回复

可以看出有两个问题

a) 仅对前 10 条记录进行“agreementID”聚合(但系统中有许多唯一的AgreementID,例如超过 5/6 lac)

b) ptp_aggs / bptp_aggs 为零,因为它们有匹配的 Lastdispositioncodes。

接下来我可以尝试什么?

Edit

这是我从 DebugInformation 获得的生成的原始查询

ApiCall.RequestBodyInBytes

{"aggs":{"Agreement_ID":{"aggs":{"ptp_aggs":{"filter":{"terms":{"lastdispositioncode":["ptp"]}}},"bptp_aggs":{"filter":{"terms":{"lastdispositioncode":["bptp"]}}},"paid_aggs":{"filter":{"terms":{"lastdispositioncode":["clmpd","dib","exceemi","odp","partpaid","pr"]}}}},"terms":{"field":"agreementid.keyword"}}},"from":0,"query":{"match_all":{}},"size":50000}

Api Call.Response 正文(以字节为单位)

"aggregations" : {
    "sterms#Agreement_ID" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 658,
      "buckets" : [
        {
          "key" : "2233585285",
          "doc_count" : 513,
          "filter#bptp_aggs" : {
            "doc_count" : 0
          },
          "filter#paid_aggs" : {
            "doc_count" : 0
          },
          "filter#ptp_aggs" : {
            "doc_count" : 513
          }
        },
        {
          "key" : "ABCD123456",
          "doc_count" : 95,
          "filter#bptp_aggs" : {
            "doc_count" : 8
          },
          "filter#paid_aggs" : {
            "doc_count" : 0
          },
          "filter#ptp_aggs" : {
            "doc_count" : 87
          }
        },
        {
          "key" : "8728441356",
          "doc_count" : 53,
          "filter#bptp_aggs" : {
            "doc_count" : 0
          },
          "filter#paid_aggs" : {
            "doc_count" : 53
          },
          "filter#ptp_aggs" : {
            "doc_count" : 0
          }
        },
        {
          "key" : "5385541121",
          "doc_count" : 39,
          "filter#bptp_aggs" : {
            "doc_count" : 0
          },
          "filter#paid_aggs" : {
            "doc_count" : 0
          },
          "filter#ptp_aggs" : {
            "doc_count" : 39
          }
        },
        {
          "key" : "VEH001001",
          "doc_count" : 30,
          "filter#bptp_aggs" : {
            "doc_count" : 0
          },
          "filter#paid_aggs" : {
            "doc_count" : 0
          },
          "filter#ptp_aggs" : {
            "doc_count" : 0
          }
        },
        {
          "key" : "2671278479",
          "doc_count" : 29,
          "filter#bptp_aggs" : {
            "doc_count" : 0
          },
          "filter#paid_aggs" : {
            "doc_count" : 29
          },
          "filter#ptp_aggs" : {
            "doc_count" : 0
          }
        },
        {
          "key" : "4937845646",
          "doc_count" : 27,
          "filter#bptp_aggs" : {
            "doc_count" : 0
          },
          "filter#paid_aggs" : {
            "doc_count" : 0
          },
          "filter#ptp_aggs" : {
            "doc_count" : 0
          }
        },
        {
          "key" : "4472873928",
          "doc_count" : 25,
          "filter#bptp_aggs" : {
            "doc_count" : 0
          },
          "filter#paid_aggs" : {
            "doc_count" : 0
          },
          "filter#ptp_aggs" : {
            "doc_count" : 0
          }
        },
        {
          "key" : "LD1736377086",
          "doc_count" : 24,
          "filter#bptp_aggs" : {
            "doc_count" : 0
          },
          "filter#paid_aggs" : {
            "doc_count" : 0
          },
          "filter#ptp_aggs" : {
            "doc_count" : 0
          }
        },
        {
          "key" : "5548762365",
          "doc_count" : 23,
          "filter#bptp_aggs" : {
            "doc_count" : 0
          },
          "filter#paid_aggs" : {
            "doc_count" : 23
          },
          "filter#ptp_aggs" : {
            "doc_count" : 0
          }
        }
      ]

None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在桶聚合中进行过滤器聚合? 的相关文章

  • 删除文件的最后 10 个字符

    我想删除文件的最后 10 个字符 说一个字符串 hello i am a c learner 是文件内的数据 我只是希望该文件是 hello i am a 文件的最后 10 个字符 即字符串 c learner 应在文件内消除 解决方案 将
  • WPF DataGrid 多选

    我读过几篇关于这个主题的文章 但很多都是来自 VS 或框架的早期版本 我想做的是从 dataGrid 中选择多行并将这些行返回到绑定的可观察集合中 我尝试创建一个属性 类型 并将其添加到可观察集合中 它适用于单个记录 但代码永远不会触发多个
  • std::list 线程push_back、front、pop_front

    std list 线程安全吗 我假设不是这样 所以我添加了自己的同步机制 我认为我有正确的术语 但我仍然遇到问题 每个函数都由单独的线程调用 Thread1 不能等待 它必须尽可能快 std list
  • 如何在 C# 中打开 Internet Explorer 属性窗口

    我正在开发一个 Windows 应用程序 我必须向用户提供一种通过打开 IE 设置窗口来更改代理设置的方法 Google Chrome 使用相同的方法 当您尝试更改 Chrome 中的代理设置时 它将打开 Internet Explorer
  • free 和 malloc 在 C 中如何工作?

    我试图弄清楚如果我尝试 从中间 释放指针会发生什么 例如 看下面的代码 char ptr char malloc 10 sizeof char for char i 0 i lt 10 i ptr i i 10 ptr ptr ptr pt
  • 为什么 GCC 不允许我创建“内联静态 std::stringstream”?

    我将直接前往 MCVE include
  • 如何在 C++ 中标记字符串?

    Java有一个方便的分割方法 String str The quick brown fox String results str split 在 C 中是否有一种简单的方法可以做到这一点 The 增强分词器 http www boost o
  • C++ 多行字符串原始文字[重复]

    这个问题在这里已经有答案了 我们可以像这样定义一个多行字符串 const char text1 part 1 part 2 part 3 part 4 const char text2 part 1 part 2 part 3 part 4
  • 访问外部窗口句柄

    我当前正在处理的程序有问题 这是由于 vista Windows 7 中增强的安全性引起的 特别是 UIPI 它阻止完整性级别较低的窗口与较高完整性级别的窗口 对话 就我而言 我想告诉具有高完整性级别的窗口进入我们的应用程序 它在 XP 或
  • WPF 数据绑定到复合类模式?

    我是第一次尝试 WPF 并且正在努力解决如何将控件绑定到使用其他对象的组合构建的类 例如 如果我有一个由两个单独的类组成的类 Comp 为了清楚起见 请注意省略的各种元素 class One int first int second cla
  • C# 列表通用扩展方法与非通用扩展方法

    这是一个简单的问题 我希望 集合类中有通用和非通用方法 例如List
  • 在 Unity 中实现 Fur with Shells 技术

    我正在尝试在 Unity 中实现皮毛贝壳技术 http developer download nvidia com SDK 10 5 direct3d Source Fur doc FurShellsAndFins pdf Fins 技术被
  • 为什么这个字符串用AesCryptoServiceProvider第二次解密时不相等?

    我在 C VS2012 NET 4 5 中的文本加密和解密方面遇到问题 具体来说 当我加密并随后解密字符串时 输出与输入不同 然而 奇怪的是 如果我复制加密的输出并将其硬编码为字符串文字 解密就会起作用 以下代码示例说明了该问题 我究竟做错
  • 实例化类时重写虚拟方法

    我有一个带有一些虚函数的类 让我们假设这是其中之一 public class AClassWhatever protected virtual string DoAThingToAString string inputString retu
  • 如何在当前 Visual Studio 主机内的 Visual Studio 扩展中调试使用 Roslyn 编译的代码?

    我有一个 Visual Studio 扩展 它使用 Roslyn 获取当前打开的解决方案中的项目 编译它并从中运行方法 程序员可以修改该项目 我已从当前 VisualStudioWorkspace 成功编译了 Visual Studio 扩
  • C# 动态/expando 对象的深度/嵌套/递归合并

    我需要在 C 中 合并 2 个动态对象 我在 stackexchange 上找到的所有内容仅涵盖非递归合并 但我正在寻找能够进行递归或深度合并的东西 非常类似于jQuery 的 extend obj1 obj2 http api jquer
  • 如何实例化 ODataQueryOptions

    我有一个工作 简化 ODataController用下面的方法 public class MyTypeController ODataController HttpGet EnableQuery ODataRoute myTypes pub
  • 相当于Linux中的导入库

    在 Windows C 中 当您想要链接 DLL 时 您必须提供导入库 但是在 GNU 构建系统中 当您想要链接 so 文件 相当于 dll 时 您就不需要链接 为什么是这样 是否有等效的 Windows 导入库 注意 我不会谈论在 Win
  • 对于某些 PDF 文件,LoadIFilter() 返回 -2147467259

    我正在尝试使用 Adob e IFilter 搜索 PDF 文件 我的代码是用 C 编写的 我使用 p invoke 来获取 IFilter 的实例 DllImport query dll SetLastError true CharSet
  • 为什么C++代码执行速度比java慢?

    我最近用 Java 编写了一个计算密集型算法 然后将其翻译为 C 令我惊讶的是 C 的执行速度要慢得多 我现在已经编写了一个更短的 Java 测试程序和一个相应的 C 程序 见下文 我的原始代码具有大量数组访问功能 测试代码也是如此 C 的

随机推荐