Elasticsearch range unique aggregations 文档
Elasticsearch range unique aggregations doc
弹性搜索 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;
我在 official forum 上发布了一个专门针对 Elasticsearch 的问题。目前,标准仪器无法解决该问题,因为对于以下查询:
'aggregations' => [
'distance_range' => [
'terms' => [
'field' => 'doc.user_id',
],
'aggregations' => [
'max_distance' => [
'max' => [
'field' => 'doc.distance'
]
]
]
]
]
在 elasticsearch 2.1 版中,没有按范围或术语分类的管道聚合器。
有几种可能的方法可以解决这个问题:
- 创建一个包含最大结果的附加索引
- 使用脚本
- 在客户端对结果求和
我用的是第三种方法。
第一个选项有一个很大的缺点:要有一个相关的附加索引,就必须对其进行控制。因此,我对这个解决方案并不满意。
第二个选项也有一些重要的限制:
计算的复杂性或对选择的影响显着影响访问时间。而且,我们还要在多个系统中维护代码。
弹性搜索 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;
我在 official forum 上发布了一个专门针对 Elasticsearch 的问题。目前,标准仪器无法解决该问题,因为对于以下查询:
'aggregations' => [
'distance_range' => [
'terms' => [
'field' => 'doc.user_id',
],
'aggregations' => [
'max_distance' => [
'max' => [
'field' => 'doc.distance'
]
]
]
]
]
在 elasticsearch 2.1 版中,没有按范围或术语分类的管道聚合器。
有几种可能的方法可以解决这个问题:
- 创建一个包含最大结果的附加索引
- 使用脚本
- 在客户端对结果求和
我用的是第三种方法。
第一个选项有一个很大的缺点:要有一个相关的附加索引,就必须对其进行控制。因此,我对这个解决方案并不满意。
第二个选项也有一些重要的限制: 计算的复杂性或对选择的影响显着影响访问时间。而且,我们还要在多个系统中维护代码。