我有许多文档代表starts_at
和ends_at
字段的事件。在给定的时间点,如果问题在starts_at
之后和ends_at
之前,则认为事件处于活动状态。ElasticSearch中的并发事件聚合
我正在寻找聚合,这应该导致日期直方图,其中每个桶包含该间隔中活动事件的数量。
到目前为止,我发现的最佳逼近方法是创建一组桶来计算每个间隔中的开始数量,以及一组相应的桶计算结束数量,然后通过减去从每个区间的结束数量开始的起始数量:
{
"size": "0",
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"and": [
{
"term": {
"_type": "event"
}
},
{
"range": {
"starts_at": {
"gte": "2015-06-14T05:25:03Z",
"lte": "2015-06-21T05:25:03Z"
}
}
}
]
}
}
},
"aggs": {
"starts": {
"date_histogram": {
"field": "starts_at",
"interval": "15m",
"extended_bounds": {
"max": "2015-06-21T05:25:04Z",
"min": "2015-06-14T05:25:04Z"
},
"min_doc_count": 0
}
},
"ends": {
"date_histogram": {
"field": "ends_at",
"interval": "15m",
"extended_bounds": {
"max": "2015-06-21T05:25:04Z",
"min": "2015-06-14T05:25:04Z"
},
"min_doc_count": 0
}
}
}
}
我正在寻找类似this solution的东西。
有没有一种方法来实现一个单一的查询?