我使用elasticsearch aggregations
返回两个不同的聚合组,一个用于当前周,一个用于前一周,我当前的周聚合看起来像这样:
"aggregations": {
"current": {
"date_histogram": {
"field": "date",
"interval": "1d",
"min_doc_count": 0,
"extended_bounds": {
"min": new Date().setDate(new Date().getDate() - 7),
"max": new Date().getDate()
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在这一点上一切都很好,即时使用min_doc_count
,extended_bounds
以填补空桶的空隙,以防万一.
在我的其他聚合上,我几乎以同样的方式重复这个过程,但我希望我的桶能够用于前一个时期!
我知道这extended_bounds
不是过滤桶,因此我想在我的聚合上添加一个过滤器,如下所示:
"aggregations": {
filtered: {
"filter" : {
"bool": {
"must": [{
"range" : {
date: {
from: new Date().setDate(new Date().getDate() - 14),
to: new Date().setDate(new Date().getDate() - 7)
}
}
}]
}
},
},
"previous": {
"date_histogram": {
"field": "date", …
Run Code Online (Sandbox Code Playgroud)