嗯,我试过一些东西,我希望它会有用。我已经利用了
的特征
Elasticsearch
LINK
更多细节。
假设我有
three
本周的文件,即
week starting from 2018-10-15
one
上周的文件,即
week starting from 2018-10-08
周内创建的用户差异
2018-10-15
会是
2
查询
POST testdateindex/_search
{
"size" : 0,
"query" : {
"bool" : {
"must" : {
"range" : {
"created" : {
"from":"now-2w",
"to":"now",
"include_lower" : true,
"include_upper" : true
}
}
}
}
},
"aggs": {
"customers_over_time": {
"date_histogram": {
"field": "created",
"interval": "week"
},
"aggs": {
"difference": {
"serial_diff": {
"buckets_path": "_count",
"lag" : 1
}
}
}
}
}
}
我用过
lag
1
因为在这种情况下,您只需要连续两周或两桶之间的差值。
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 0,
"hits": []
},
"aggregations": {
"customers_over_time": {
"buckets": [
{
"key_as_string": "2018-10-08T00:00:00.000Z",
"key": 1538956800000,
"doc_count": 1
},
{
"key_as_string": "2018-10-15T00:00:00.000Z",
"key": 1539561600000,
"doc_count": 3,
"difference": {
"value": 2
}
}
]
}
}
}
结果将显示该周所有文档的计数以及
difference
注意,第一个bucket没有
差异
希望有帮助!