简体   繁体   English

弹性搜索查询最大值aggs

[英]Elastic search query max value aggs

I have data like this: 我有这样的数据:

Name     Fees Collected     Date
Name1     100              2017-05-01T12:00:00
Name1     200              2017-05-02T12:00:00
Name2     500              2017-05-05T12:00:00
Name2     600              2017-05-06T12:00:00
Name3     1000             2017-05-010T12:00:00
Name3     1100             2017-05-011T12:00:00
Name4     1500             2017-05-011T12:00:00

How can i write a query to return the aggregation of filtered/grouped to the max Date with min doc count of 2 for each group? 如何编写查询以将过滤/分组的聚合返回到最大日期,每个组的最小文档数为2?

I expect the following output: 我期待以下输出:

Name     Fees Collected   Date  
Name1     200             2017-05-02T12:00:00
Name2     600             2017-05-06T12:00:00
Name3     1100            2017-05-011T12:00:00

Finally, I would get the aggregation as following 最后,我会得到如下聚合

"aggregations" {
    "Fees Collected " : "1900" //(200+600+1100)
    }

Is there anyway to achieve this in elastic search? 无论如何在弹性搜索中实现这一点? Thank you.. 谢谢..

There is a way! 有一种方法!

First you need a terms aggregation on "Name" field with addition of "min_doc_count": 3. Then a sub max_aggregation on field "Date". 首先,您需要在“名称”字段中添加术语聚合,并添加“min_doc_count”:3。然后在字段“日期”上进行子max_aggregation。

somthing like this: 这样的事:

"aggs": {
 "split_by_name": {
  "terms": {
    "field": "Name",
    "min_doc_count": 3
  },
  "aggs": {
    "max_date": {
      "max": {
        "field": "Date"
        }
      }
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM