获取汇总作业 API

编辑

在 8.11.0 中已弃用。

汇总将在未来版本中删除。请改用降采样

检索汇总作业的配置、统计信息和状态。

请求

编辑

GET _rollup/job/<job_id>

先决条件

编辑
  • 如果启用了 Elasticsearch 安全功能,您必须具有 monitormonitor_rollupmanagemanage_rollup 集群权限才能使用此 API。有关更多信息,请参阅安全权限

描述

编辑

该 API 可以返回单个汇总作业或所有汇总作业的详细信息。

此 API 仅返回活动(STARTEDSTOPPED)作业。如果某个作业已创建、运行一段时间然后被删除,则此 API 不会返回有关该作业的任何详细信息。

有关历史汇总作业的详细信息,汇总功能 API 可能更有用。

路径参数

编辑
<job_id>
(可选,字符串)汇总作业的标识符。如果它是 _all 或省略,则 API 返回所有汇总作业。

响应主体

编辑
jobs

(数组)汇总作业资源的数组。

汇总作业资源的属性
config
(对象)包含汇总作业的配置。此信息与通过创建作业 API创建作业时提供的配置相同。
stats
(对象)包含有关汇总作业的瞬时统计信息,例如已处理的文档数和已索引的汇总摘要文档数。这些统计信息不会持久化。如果节点重新启动,则这些统计信息将重置。
status

(对象)包含汇总作业的索引器的当前状态。可能的值及其含义是

  • stopped 表示索引器已暂停,即使其 cron 间隔触发也不会处理数据。
  • started 表示索引器正在运行,但未主动索引数据。当 cron 间隔触发时,作业的索引器将开始处理数据。
  • indexing 表示索引器正在主动处理数据并创建新的汇总文档。在此状态下,任何后续的 cron 间隔触发都将被忽略,因为作业已经通过先前的触发处于活动状态。
  • abort 是一种瞬时状态,通常用户不会看到。如果任务需要因某种原因(作业已删除、遇到无法恢复的错误等)而关闭,则会使用它。在设置 abort 状态后不久,作业将从集群中删除自身。

示例

编辑

如果我们已经创建了一个名为 sensor 的汇总作业,则可以使用以下方法检索有关该作业的详细信息

resp = client.rollup.get_jobs(
    id="sensor",
)
print(resp)
response = client.rollup.get_jobs(
  id: 'sensor'
)
puts response
const response = await client.rollup.getJobs({
  id: "sensor",
});
console.log(response);
GET _rollup/job/sensor

该 API 产生以下响应

{
  "jobs": [
    {
      "config": {
        "id": "sensor",
        "index_pattern": "sensor-*",
        "rollup_index": "sensor_rollup",
        "cron": "*/30 * * * * ?",
        "groups": {
          "date_histogram": {
            "fixed_interval": "1h",
            "delay": "7d",
            "field": "timestamp",
            "time_zone": "UTC"
          },
          "terms": {
            "fields": [
              "node"
            ]
          }
        },
        "metrics": [
          {
            "field": "temperature",
            "metrics": [
              "min",
              "max",
              "sum"
            ]
          },
          {
            "field": "voltage",
            "metrics": [
              "avg"
            ]
          }
        ],
        "timeout": "20s",
        "page_size": 1000
      },
      "status": {
        "job_state": "stopped"
      },
      "stats": {
        "pages_processed": 0,
        "documents_processed": 0,
        "rollups_indexed": 0,
        "trigger_count": 0,
        "index_failures": 0,
        "index_time_in_ms": 0,
        "index_total": 0,
        "search_failures": 0,
        "search_time_in_ms": 0,
        "search_total": 0,
        "processing_time_in_ms": 0,
        "processing_total": 0
      }
    }
  ]
}

由于我们在端点的 URL 中请求了单个作业,因此 jobs 数组包含单个作业(id: sensor)。如果我们添加另一个作业,我们可以看到如何处理多作业响应

resp = client.rollup.put_job(
    id="sensor2",
    index_pattern="sensor-*",
    rollup_index="sensor_rollup",
    cron="*/30 * * * * ?",
    page_size=1000,
    groups={
        "date_histogram": {
            "field": "timestamp",
            "fixed_interval": "1h",
            "delay": "7d"
        },
        "terms": {
            "fields": [
                "node"
            ]
        }
    },
    metrics=[
        {
            "field": "temperature",
            "metrics": [
                "min",
                "max",
                "sum"
            ]
        },
        {
            "field": "voltage",
            "metrics": [
                "avg"
            ]
        }
    ],
)
print(resp)

resp1 = client.rollup.get_jobs(
    id="_all",
)
print(resp1)
const response = await client.rollup.putJob({
  id: "sensor2",
  index_pattern: "sensor-*",
  rollup_index: "sensor_rollup",
  cron: "*/30 * * * * ?",
  page_size: 1000,
  groups: {
    date_histogram: {
      field: "timestamp",
      fixed_interval: "1h",
      delay: "7d",
    },
    terms: {
      fields: ["node"],
    },
  },
  metrics: [
    {
      field: "temperature",
      metrics: ["min", "max", "sum"],
    },
    {
      field: "voltage",
      metrics: ["avg"],
    },
  ],
});
console.log(response);

const response1 = await client.rollup.getJobs({
  id: "_all",
});
console.log(response1);
PUT _rollup/job/sensor2 
{
  "index_pattern": "sensor-*",
  "rollup_index": "sensor_rollup",
  "cron": "*/30 * * * * ?",
  "page_size": 1000,
  "groups": {
    "date_histogram": {
      "field": "timestamp",
      "fixed_interval": "1h",
      "delay": "7d"
    },
    "terms": {
      "fields": [ "node" ]
    }
  },
  "metrics": [
    {
      "field": "temperature",
      "metrics": [ "min", "max", "sum" ]
    },
    {
      "field": "voltage",
      "metrics": [ "avg" ]
    }
  ]
}

GET _rollup/job/_all 

我们创建一个名为 sensor2 的第二个作业

然后通过在 GetJobs API 中使用 _all 请求所有作业

这将产生以下响应

{
  "jobs": [
    {
      "config": {
        "id": "sensor2",
        "index_pattern": "sensor-*",
        "rollup_index": "sensor_rollup",
        "cron": "*/30 * * * * ?",
        "groups": {
          "date_histogram": {
            "fixed_interval": "1h",
            "delay": "7d",
            "field": "timestamp",
            "time_zone": "UTC"
          },
          "terms": {
            "fields": [
              "node"
            ]
          }
        },
        "metrics": [
          {
            "field": "temperature",
            "metrics": [
              "min",
              "max",
              "sum"
            ]
          },
          {
            "field": "voltage",
            "metrics": [
              "avg"
            ]
          }
        ],
        "timeout": "20s",
        "page_size": 1000
      },
      "status": {
        "job_state": "stopped"
      },
      "stats": {
        "pages_processed": 0,
        "documents_processed": 0,
        "rollups_indexed": 0,
        "trigger_count": 0,
        "index_failures": 0,
        "index_time_in_ms": 0,
        "index_total": 0,
        "search_failures": 0,
        "search_time_in_ms": 0,
        "search_total": 0,
        "processing_time_in_ms": 0,
        "processing_total": 0
      }
    },
    {
      "config": {
        "id": "sensor",
        "index_pattern": "sensor-*",
        "rollup_index": "sensor_rollup",
        "cron": "*/30 * * * * ?",
        "groups": {
          "date_histogram": {
            "fixed_interval": "1h",
            "delay": "7d",
            "field": "timestamp",
            "time_zone": "UTC"
          },
          "terms": {
            "fields": [
              "node"
            ]
          }
        },
        "metrics": [
          {
            "field": "temperature",
            "metrics": [
              "min",
              "max",
              "sum"
            ]
          },
          {
            "field": "voltage",
            "metrics": [
              "avg"
            ]
          }
        ],
        "timeout": "20s",
        "page_size": 1000
      },
      "status": {
        "job_state": "stopped"
      },
      "stats": {
        "pages_processed": 0,
        "documents_processed": 0,
        "rollups_indexed": 0,
        "trigger_count": 0,
        "index_failures": 0,
        "index_time_in_ms": 0,
        "index_total": 0,
        "search_failures": 0,
        "search_time_in_ms": 0,
        "search_total": 0,
        "processing_time_in_ms": 0,
        "processing_total": 0
      }
    }
  ]
}