栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

计算data_histogram聚合中的差异

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

计算data_histogram聚合中的差异

好吧,我已经尝试过一些东西,希望对您有用。我已经利用的 序列差异汇总
功能,

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    } }         }    }  }}

我使用了

lag
as,
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
因为那一周之前我还没有创建任何文档。

希望能帮助到你!



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/397854.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号