【发布时间】:2016-08-24 14:03:09
【问题描述】:
我对 Elasticsearch 很陌生,我无法根据访问范围构建直方图。我什至不确定是否可以通过在 Elasticsearch 中使用单个查询来创建这种图表,但我觉得可以通过管道聚合或脚本聚合来实现。
这是我正在使用的测试数据集:
PUT /test_histo
{ "settings": { "number_of_shards": 1 }}
PUT /test_histo/_mapping/visit
{
"properties": {
"user": {"type": "string" },
"datevisit": {"type": "date"},
"page": {"type": "string"}
}
}
POST test_histo/visit/_bulk
{"index":{"_index":"test_histo","_type":"visit"}}
{"user":"John","page":"home.html","datevisit":"2015-11-25"}
{"index":{"_index":"test_histo","_type":"visit"}}
{"user":"Jean","page":"productXX.hmtl","datevisit":"2015-11-25"}
{"index":{"_index":"test_histo","_type":"visit"}}
{"user":"Robert","page":"home.html","datevisit":"2015-11-25"}
{"index":{"_index":"test_histo","_type":"visit"}}
{"user":"Mary","page":"home.html","datevisit":"2015-11-25"}
{"index":{"_index":"test_histo","_type":"visit"}}
{"user":"Mary","page":"media_center.html","datevisit":"2015-11-25"}
{"index":{"_index":"test_histo","_type":"visit"}}
{"user":"John","page":"home.html","datevisit":"2015-11-25"}
{"index":{"_index":"test_histo","_type":"visit"}}
{"user":"John","page":"media_center.html","datevisit":"2015-11-26"}
如果我们考虑范围 [1,2[, [2,3[, [3, inf.[
预期的结果应该是:
- [1,2[ = 2
- [2,3[ = 1
- [3, inf.[ = 1
迄今为止,我为找到显示客户访问频率的直方图所做的所有努力都没有成功。我很高兴有一些提示、技巧或想法来解决我的问题。
【问题讨论】:
-
您能否更具体地说明您期望的输出类型? 如果我们考虑范围 [1,2[, [2,3[, [3, inf.[ 是什么意思?
-
我想知道客户的访问频率,即他们多久访问一次?本例中 [1,2[ 表示周期时间一次,[2,3[ 表示周期时间两次,....周期时间在这里不定但它可能是一周或一个月等。
-
我是否应该断定不可能从所描述的日志中获得客户访问频率?
-
你能解释一下上面例子中的 [1,2[ = 2 和 [2,3[ = 1 是怎么回事?
-
[1,2[ = 2 因为有 2 个用户在此期间访问过网站一次(我的数据集中的 Jean 和 Robert),[2,3[=1 因为有 1 个用户访问过两次(Mary ), etc...[a,b[ = x 表示
访问者在该期间至少有 次访问且少于 次访问