3
有没有办法将聚合存储桶的key
值用作子聚合中的参数?从父聚合获取参数的子聚合脚本
,如被索引:
{
"id": 152,
"description": "cool stuff",
"datesWithTotal" : [
{
"date" : "2014-02-02T00:00:00",
"total" : 47.2
},
{
"date" : "2014-02-03T00:00:00",
"total" : 51.2
},
{
"date" : "2014-02-04T00:00:00",
"total" : 56.4
}
]
}
我想用这将基于当前parentbucket.key
值
{
"aggs": {
"histo": {
"date_histogram": {
"field": "datesWithTotal.date",
"interval": "1d"
},
"aggs": {
"script-test": {
"scripted_metric": {
"init_script": "_agg['sum'] = 0",
"map_script": "_agg.sum += (PARENTBUCKET.KEY == 'somevalue' ? 1 : 0)",
"combine_script": "return _agg.sum"
}
}
}
}
}
}
我已经执行一些操作的子聚集执行date_histogram
聚集已经以这种方式使用了一些脚本,但是每个脚本都没有使用父类中的任何内容,只是简单的整数参数。