索引汇总 API
使用索引汇总操作以编程方式处理索引汇总任务。
目录
创建或更新索引汇总任务
1.0 版引入
创建或更新索引汇总任务。您必须提供 seq_no
和 primary_term
参数。
请求
PUT _plugins/_rollup/jobs/<rollup_id> // Create
PUT _plugins/_rollup/jobs/<rollup_id>?if_seq_no=1&if_primary_term=1 // Update
{
"rollup": {
"source_index": "nyc-taxi-data",
"target_index": "rollup-nyc-taxi-data",
"target_index_settings":{
"index.number_of_shards": 1,
"index.number_of_replicas": 1,
"index.codec": "best_compression"
},
"schedule": {
"interval": {
"period": 1,
"unit": "Days"
}
},
"description": "Example rollup job",
"enabled": true,
"page_size": 200,
"delay": 0,
"roles": [
"rollup_all",
"nyc_taxi_all",
"example_rollup_index_all"
],
"continuous": false,
"dimensions": [
{
"date_histogram": {
"source_field": "tpep_pickup_datetime",
"fixed_interval": "1h",
"timezone": "America/Los_Angeles"
}
},
{
"terms": {
"source_field": "PULocationID"
}
}
],
"metrics": [
{
"source_field": "passenger_count",
"metrics": [
{
"avg": {}
},
{
"sum": {}
},
{
"max": {}
},
{
"min": {}
},
{
"value_count": {}
}
]
}
]
}
}
您可以指定以下选项。
选项 | 描述 | 类型 | 必需 |
---|---|---|---|
source_index | 检测器名称。 | 字符串 | 是 |
target_index | 指定汇总数据要摄取到的目标索引。您可以创建新的目标索引或使用现有索引。目标索引不能是原始数据和汇总数据的组合。此字段支持动态生成的索引名称,例如 rollup_{{ctx.source_index}} ,其中 source_index 不能包含通配符。 | 字符串 | 是 |
target_index_settings | 指定在汇总期间应用于创建的目标索引的任何索引设置。 | 对象 | 否 |
schedule | 索引汇总任务的调度,可以是时间间隔或 cron 表达式。 | 对象 | 是 |
schedule.interval | 指定汇总任务的执行频率。 | 对象 | 否 |
schedule.interval.start_time | 时间间隔的开始时间。 | 时间戳 | 是 |
schedule.interval.period | 定义时间间隔周期。 | 字符串 | 是 |
schedule.interval.unit | 指定时间间隔的时间单位。 | 字符串 | 是 |
schedule.interval.cron | (可选)指定 cron 表达式来定义汇总频率。 | 列表 | 否 |
schedule.interval.cron.expression | 指定 Unix cron 表达式。 | 字符串 | 是 |
schedule.interval.cron.timezone | 指定 IANA 时区数据库定义的时区。默认为 UTC。 | 字符串 | 否 |
description | (可选)描述汇总任务。 | 字符串 | 否 |
enabled | 如果为 true,则调度索引汇总任务。默认为 true 。 | 布尔型 | 是 |
continuous | 指定索引汇总任务是永久连续汇总数据,还是在当前数据集上执行一次后停止。默认为 false 。 | 布尔型 | 是 |
error_notification | 设置用于错误通知的 Mustache 消息模板。例如,如果索引汇总任务失败,系统会向 Slack 频道发送消息。 | 对象 | 否 |
page_size | 指定在汇总期间每次分页的桶数量。 | 数字 | 是 |
delay | 延迟执行索引汇总任务的毫秒数。 | 长整型 | 否 |
dimensions | 指定聚合以创建汇总时间窗口的维度。支持的组包括 terms 、histogram 和 date_histogram 。更多信息请参阅桶聚合。 | 数组 | 是 |
metrics | 指定一个对象列表,表示您要计算的字段和度量。支持的度量包括 sum 、max 、min 、value_count 和 avg 。更多信息请参阅度量聚合。 | 数组 | 否 |
示例响应
{
"_id": "<rollup_id>",
"_version": 3,
"_seq_no": 1,
"_primary_term": 1,
"rollup": {
"rollup_id": "<rollup_id>",
"enabled": true,
"schedule": {
"interval": {
"start_time": 1680159934649,
"period": 1,
"unit": "Days",
"schedule_delay": 0
}
},
"last_updated_time": 1680159934649,
"enabled_time": 1680159934649,
"description": "Example rollup job",
"schema_version": 17,
"source_index": "nyc-taxi-data",
"target_index": "rollup-nyc-taxi-data",
"metadata_id": null,
"page_size": 200,
"delay": 0,
"continuous": false,
"dimensions": [
{
"date_histogram": {
"fixed_interval": "1h",
"source_field": "tpep_pickup_datetime",
"target_field": "tpep_pickup_datetime",
"timezone": "America/Los_Angeles"
}
},
{
"terms": {
"source_field": "PULocationID",
"target_field": "PULocationID"
}
}
],
"metrics": [
{
"source_field": "passenger_count",
"metrics": [
{
"avg": {}
},
{
"sum": {}
},
{
"max": {}
},
{
"min": {}
},
{
"value_count": {}
}
]
}
]
}
}
获取索引汇总任务
1.0 版引入
根据 rollup_id
返回索引汇总任务的所有信息。
请求
GET _plugins/_rollup/jobs/<rollup_id>
示例响应
{
"_id": "my_rollup",
"_seqNo": 1,
"_primaryTerm": 1,
"rollup": { ... }
}
删除索引汇总任务
1.0 版引入
根据 rollup_id
删除索引汇总任务。
请求
DELETE _plugins/_rollup/jobs/<rollup_id>
示例响应
200 OK
启动或停止索引汇总任务
1.0 版引入
启动或停止索引汇总任务。
请求
POST _plugins/_rollup/jobs/<rollup_id>/_start
POST _plugins/_rollup/jobs/<rollup_id>/_stop
示例响应
200 OK
解释索引汇总任务
1.0 版引入
返回索引汇总任务的详细元数据信息及其当前进度。
请求
GET _plugins/_rollup/jobs/<rollup_id>/_explain
示例响应
{
"example_rollup": {
"rollup_id": "example_rollup",
"last_updated_time": 1602014281,
"continuous": {
"next_window_start_time": 1602055591,
"next_window_end_time": 1602075591
},
"status": "running",
"failure_reason": null,
"stats": {
"pages_processed": 342,
"documents_processed": 489359,
"rollups_indexed": 3420,
"index_time_in_ms": 30495,
"search_time_in_ms": 584922
}
}
}