Elasticsearch 2.1.1.该索引包含关于运动员跳跃的记录。每个运动员都有几次跳跃的尝试。该文件的结构如下:
{
'event_at' : '2015-01-01T12:12:10', - date of jump
'user_id' : 2142, - athlete’s id
'distance' : 4 - result
}有必要得到以下结果:
{'distance_range' :
{'*-5' : 12, - the number of unique athletes with the maximum jump score in the range from 0 to 5
'6-10': 14,- the number of unique athletes with the maximum jump score in the range from 6 to 10
'11-15': 5 - the number of unique athletes with the maximum jump score in the range from 11 to 15
}
}我设法得到了每个运动员跳高得分的最大值,但我不知道如何在更高的水平上获得这个成绩。
使用SQL可以如下所示:
SELECT `distace_range`, count(*) FROM (
SELECT
`user_id`,
IF(MAX(`distace`) <=5,
'*-5',
IF(MAX(`distace`) >= 6 AND MAX(`distace`) >= 10,
'6-10',
'11-15'
)
) `distace_range`
FROM `events`
GROUP BY `user_id`
) t
GROUP BY `distace_range;发布于 2016-02-16 06:55:26
我在官方论坛上发表了一个专门针对Elasticsearch的问题。目前,这个问题无法通过标准仪器解决,因为对于以下查询:
'aggregations' => [
'distance_range' => [
'terms' => [
'field' => 'doc.user_id',
],
'aggregations' => [
'max_distance' => [
'max' => [
'field' => 'doc.distance'
]
]
]
]
]在elasticsearch版本2.1中,不存在按范围或术语划分的管道聚合器。
解决这个问题有几种可能的方法:
我用了第三种方法。
第一个选项有一个很大的缺点:要有一个相关的附加索引,就必须控制它。因此,我对这个解决办法并不满意。
第二个选项也有一些重要的限制:计算的复杂性或对选择的影响对访问时间有很大影响。此外,我们还必须在多个系统中维护代码。
https://stackoverflow.com/questions/34836197
复制相似问题