Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Search 弹性搜索查询最大值aggs_Search_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Grouping_Aggregation - Fatal编程技术网 elasticsearch,grouping,aggregation,Search,elasticsearch,Grouping,Aggregation" /> elasticsearch,grouping,aggregation,Search,elasticsearch,Grouping,Aggregation" />

Search 弹性搜索查询最大值aggs

Search 弹性搜索查询最大值aggs,search,elasticsearch,grouping,aggregation,Search,elasticsearch,Grouping,Aggregation,我有这样的数据: 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

我有这样的数据:

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
如何编写查询以将过滤/分组的聚合返回到每个组的最小文档数为2的最大日期

我期望得到以下结果:

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
最后,我将得到如下的聚合

"aggregations" {
    "Fees Collected " : "1900" //(200+600+1100)
    }
在弹性搜索中是否有实现这一点的方法? 谢谢你。

有办法

首先,您需要在“Name”字段上添加一个术语聚合,并添加“min_doc_count”:3。 然后在字段“日期”上进行次最大值聚合

像这样的事情:

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