我在ElasticSearch(2.4)聚合中将scripted_metric与日期范围结合在一起。
因此,如果我理解正确,脚本(初始化,映射,合并,缩小)将应用于指定的每个日期范围。是吗?
{
"query": {
"match_all": {}
},
"aggs": {
"kpi_over_time": {
"aggs": {
"profit": {
"scripted_metric": {
"init_script": "",
"map_script": "",
"combine_script": "",
"reduce_script": ""
}
}
},
"date_range": {
"field": "date",
"ranges": [{
"from": "2017-09-01||-12M",
"to": "2017-09-01"
},
{
"from": "2017-10-01||-12M",
"to": "2017-10-01"
},
{
"from": "2017-11-01||-12M",
"to": "2017-11-01"
},
{
"from": "2017-12-01||-12M",
"to": "2017-12-01"
}
]
}
}
}
}
是否可以在scripted_metric脚本中访问计算的日期范围的“从”和“到”?
例如,在“ init_script”中可能有类似
的内容 _agg["from"] = <something_about_the current_date_range_query>["from"]