版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/huochen1994/article/details/81504877
Elasticsearch Rolling up historical data
Overview
And while we continue to believe that most data tends to have value over a long period of time, the relative value of the data can decrease as it ages
虽然大多数的数据在很长一段时间内都具有价值,但数据的相对价值会随着时间的增长而降低。
通过汇总数据来减少存储成本成为了一种选择。
Elasticsearch目前支持配置一个定时任务自动把历史数据汇总到一个新的索引当中。
API Quick Reference
About Job
获取已有任务列表
GET /_xpack/rollup/job/_all
新增一个任务
新增一个id为video_test的任务
PUT /_xpack/rollup/job/video_test
{
# 源索引
"index_pattern": "sinavideo_dispatcher-*",
# 汇总结果索引
"rollup_index": "video_test_2",
# 任务调用规则(crontable)
"cron": "*/1 * * * * ?",
"page_size" :1000,
# 聚合规则
"groups" : {
"date_histogram": {
"field": "@timestamp",
# 聚合粒度
"interval": "5m",
# 数据延迟
"delay": "15m"
},
"terms": {
"fields": ["domain", "http_code"]
}
},
# 聚合指标
"metrics": [
{
"field": "body_bytes_send",
"metrics": ["avg"]
}
]
}
具体各参数参照rollup-job-config
任务启停
每一个任务默认是停止的,需要调用接口启动
POST /_xpack/rollup/job/video_test/_start
停止
POST /_xpack/rollup/job/video_test/_stop
获取任务配置
获取任务配置信息,其中被删除的任务无法查看
GET /_xpack/rollup/job/video_test/
获取索引对应的任务元数据信息
GET /_xpack/rollup/data/sinavideo_dispatcher-*
About Search
无论是实时数据还是聚合数据都支持_rollup_search
和_search
两个接口。但是如果要获取聚合的结果,需要调用_rollup_search
接口。
以下是获取每个域名每5分钟的平均流量大小:
GET video_test_2/_rollup_search
{
"size": 0,
"aggregations": {
"timeline": {
"date_histogram": {
"field": "@timestamp",
"interval": "5m"
},
"aggs": {
"domains": {
"terms": {
"field": "domain",
"size": 10
},
"aggs": {
"avg_body": {
"avg": {
"field": "body_bytes_send"
}
}
}
}
}
}
}
}
_rollup_search
接口支持同时查询实时数据和汇总后的数据。当实时数据和汇总数据存在重叠时,将默认优先使用实时数据来提高数据准确性
GET sinavideo_dispatcher-*,video_test_2/_rollup_search
{
...
}
Limitations
- Only one Rollup index per search(查询时仅能指定一个汇总索引,对实时索引没有限定)
- Can only aggregate what’s been stored(没有汇总的结果当然无法搜索)
- Interval Granularity(配置任务时定义了聚合时间粒度,后续无法获取小于这个粒度的汇总数据)
- Limited aggregation components(有限的聚合方法)
- Limited querying components(有限的查询方法)
存在的问题
- Job目前无法修改
- Kibana暂时不支持
_rollup_search