【发布时间】:2014-08-15 08:26:14
【问题描述】:
我正在运行 Elasticsearch v1.2.2。
我有一个这样的文档集合
[
{ id: 1, source: { host: 'test.localhost', timestamp: 1407937236, loading_time: 2.841917 } },
{ id: 2, source: { host: 'test.localhost', timestamp: 1407937262, loading_time: 2.009191 } },
{ id: 3, source: { host: 'test.localhost', timestamp: 1407937322, loading_time: 2.084986 } },
{ id: 4, source: { host: 'test.localhost', timestamp: 1407937382, loading_time: 2.869245 } },
{ id: 5, source: { host: 'test.localhost', timestamp: 1407937442, loading_time: 2.559648 } },
...
]
(基本上所有分钟我都对内部主机运行测试,返回加载时间。)
现在我想生成一个概览图:
- 按 30 分钟分组的时间戳
- 返回(该分组的)最大加载时间
- host 是特定的东西
- 在特定时间戳范围之间
- 按时间戳排序
由于我是 Elasticsearch 的新手,我什至不知道这一切是否可行。
在 MySQL 中是这样的
SELECT (FLOOR(`timestamp` / 1800) * 1800) AS timestamp
MAX(`loading_time`) AS loading_time
FROM `elasticsearch_table`
GROUP BY (FLOOR(`timestamp` / 1800) * 1800)
WHERE `host` = 'test.localhost'
AND `timestamp` BETWEEN 1407937236 AND 1407937442
ORDER BY `timestamp` ASC
(不确定这个 MySQL 查询是否有效,但它应该让您了解我想要实现的目标。)
【问题讨论】:
标签: mysql elasticsearch