好吧,我已经尝试过一些东西,希望对您有用。我已经利用的 序列差异汇总
功能,
Elasticsearch您可以参考此链接以获取更多详细信息。
假设我有
three本周的文件,即
week starting from 2018-10-15只有
one上周的文件,即
week startingfrom 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 } } } } }}我使用了
lagas,
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上面的json部分,该计数将保留与上周的计数差异。
请注意,第一个存储桶没有,
difference因为那一周之前我还没有创建任何文档。
希望能帮助到你!



