---
type: api
title: Create a rollup job
description: WARNING: From 8.15.0, calling this API in a cluster with no rollup usage will fail with a message about the deprecation and planned removal of rollup features. A cluster needs to contain either a rollup job or a rollup index in order for this API to be allowed to run.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-rollup-put-job
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-rollup-put-job
products:
  - Elasticsearch
---

# Create a rollup job

deprecated

Availability: 6.3+

## Paths

- `PUT` `/_rollup/job/{id}`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#bearerauth)

#### Path Parameters

- `id` (string Id)
  Identifier for the rollup job. This can be any alphanumeric string and uniquely identifies the
data that is associated with the rollup job. The ID is persistent; it is stored with the rolled
up data. If you create a job, let it run for a while, then delete the job, the data that the job
rolled up is still be associated with this job ID. You cannot create a new job with the same ID
since that could lead to problems with mismatched job configurations.

## Description

WARNING: From 8.15.0, calling this API in a cluster with no rollup usage will fail with a message about the deprecation and planned removal of rollup features. A cluster needs to contain either a rollup job or a rollup index in order for this API to be allowed to run.

The rollup job configuration contains all the details about how the job should run, when it indexes documents, and what future queries will be able to run against the rollup index.

There are three main sections to the job configuration: the logistical details about the job (for example, the cron schedule), the fields that are used for grouping, and what metrics to collect for each group.

Jobs are created in a `STOPPED` state. You can start them with the start rollup jobs API.

## Required authorization

* Cluster privileges: `manage`,`manage_rollup`

## Request Body

`application/json`

- `cron` (string) — required
  A cron string which defines the intervals when the rollup job should be executed. When the interval
triggers, the indexer attempts to rollup the data in the index pattern. The cron pattern is unrelated
to the time interval of the data being rolled up. For example, you may wish to create hourly rollups
of your document but to only run the indexer on a daily basis at midnight, as defined by the cron. The
cron pattern is defined just like a Watcher cron schedule.
- `groups` ({} Groupings) — required
  Defines the grouping fields and aggregations that are defined for this rollup job. These fields will then be
available later for aggregating into buckets. These aggs and fields can be used in any combination. Think of
the groups configuration as defining a set of tools that can later be used in aggregations to partition the
data. Unlike raw data, we have to think ahead to which fields and aggregations might be used. Rollups provide
enough flexibility that you simply need to determine which fields are needed, not in what order they are needed.
  - `date_histogram` ({} DateHistogramGrouping) — optional
    A date histogram group aggregates a date field into time-based buckets.
This group is mandatory; you currently cannot roll up documents without a timestamp and a `date_histogram` group.
    - `delay` (string Duration) — optional
      How long to wait before rolling up new documents.
By default, the indexer attempts to roll up all data that is available.
However, it is not uncommon for data to arrive out of order.
The indexer is unable to deal with data that arrives after a time-span has been rolled up.
You need to specify a delay that matches the longest period of time you expect out-of-order data to arrive.
    - `field` (string Field) — required
      The date field that is to be rolled up.
    - `format` (string) — optional
    - `interval` (string Duration) — optional
    - `calendar_interval` (string Duration) — optional
      The interval of time buckets to be generated when rolling up.
    - `fixed_interval` (string Duration) — optional
      The interval of time buckets to be generated when rolling up.
    - `time_zone` (string) — optional
      Defines what `time_zone` the rollup documents are stored as.
Unlike raw data, which can shift timezones on the fly, rolled documents have to be stored with a specific timezone.
By default, rollup documents are stored in `UTC`.
  - `histogram` ({} HistogramGrouping) — optional
    The histogram group aggregates one or more numeric fields into numeric histogram intervals.
    - `fields` (string Fields) — required
      The set of fields that you wish to build histograms for.
All fields specified must be some kind of numeric.
Order does not matter.
    - `interval` (number) — required
      The interval of histogram buckets to be generated when rolling up.
For example, a value of `5` creates buckets that are five units wide (`0-5`, `5-10`, etc).
Note that only one interval can be specified in the histogram group, meaning that all fields being grouped via the histogram must share the same interval.
  - `terms` ({} TermsGrouping) — optional
    The terms group can be used on keyword or numeric fields to allow bucketing via the terms aggregation at a later point.
The indexer enumerates and stores all values of a field for each time-period.
This can be potentially costly for high-cardinality groups such as IP addresses, especially if the time-bucket is particularly sparse.
    - `fields` (string Fields) — required
      The set of fields that you wish to collect terms for.
This array can contain fields that are both keyword and numerics.
Order does not matter.
- `index_pattern` (string) — required
  The index or index pattern to roll up. Supports wildcard-style patterns (`logstash-*`). The job attempts to
rollup the entire index or index-pattern.
- `metrics` ([] FieldMetric) — optional
  Defines the metrics to collect for each grouping tuple. By default, only the doc_counts are collected for each
group. To make rollup useful, you will often add metrics like averages, mins, maxes, etc. Metrics are defined
on a per-field basis and for each field you configure which metric should be collected.
  - `field` (string Field) — required
    The field to collect metrics for. This must be a numeric of some kind.
  - `metrics` ([] enum Metric) — required
    An array of metrics to collect for the field. At least one metric must be configured.
    Values: `min`, `max`, `sum`, `avg`, `value_count`
- `page_size` (number) — required
  The number of bucket results that are processed on each iteration of the rollup indexer. A larger value tends
to execute faster, but requires more memory during processing. This value has no effect on how the data is
rolled up; it is merely used for tweaking the speed or memory cost of the indexer.
- `rollup_index` (string IndexName) — required
  The index that contains the rollup results. The index can be shared with other rollup jobs. The data is stored so that it doesn’t interfere with unrelated jobs.
- `timeout` (string Duration · default: 20s) — optional
  Time to wait for the request to complete.
- `headers` (HttpHeaders) — optional

## Response

`application/json`

- `acknowledged` (boolean)
  For a successful response, this value is always true. On failure, an exception is returned instead.
## Code Examples

#### Console

```console
PUT _rollup/job/sensor
{
  "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" ]
    }
  ]
}
```

#### JavaScript

```javascript
const response = await client.rollup.putJob({
  id: "sensor",
  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"],
    },
  ],
});
```

#### Python

```python
resp = client.rollup.put_job(
    id="sensor",
    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"
            ]
        }
    ],
)
```

#### curl

```curl
curl -X PUT "$ELASTICSEARCH_URL/_rollup/job/sensor" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "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"
        ]
      }
    ]
  }'
```

#### Java

```java
client.rollup().putJob(p -> p
    .cron("*/30 * * * * ?")
    .groups(g -> g
        .dateHistogram(d -> d
            .delay(de -> de
                .time("7d")
            )
            .field("timestamp")
            .fixedInterval(f -> f
                .time("1h")
            )
        )
        .terms(t -> t
            .fields("node")
        )
    )
    .id("sensor")
    .indexPattern("sensor-*")
    .metrics(List.of(FieldMetric.of(f -> f
            .field("temperature")
            .metrics(List.of(Metric.Min,Metric.Max,Metric.Sum))),FieldMetric.of(f -> f
            .field("voltage")
            .metrics(Metric.Avg))))
    .pageSize(1000)
    .rollupIndex("sensor_rollup")
);
```

#### C#

```c#
var response = await client.Rollup
    .PutJobAsync(id: "sensor", d1 => d1
        .Cron("*/30 * * * * ?")
        .Groups(d2 => d2
            .DateHistogram(d3 => d3
                .Delay("7d")
                .Field(x => x.Timestamp)
                .FixedInterval("1h")
            )
            .Terms(d3 => d3
                .Fields(x => x.Node)
            )
        )
        .IndexPattern("sensor-*")
        .Metrics(d2 => d2
            .Field(x => x.Temperature)
            .Metrics(Metric.Min, Metric.Max, Metric.Sum), d2 => d2
            .Field(x => x.Voltage)
            .Metrics(Metric.Avg)
        )
        .PageSize(1000)
        .RollupIndex("sensor_rollup")
    );
```

#### PHP

```php
$resp = $client->rollup()->putJob([
    "id" => "sensor",
    "body" => [
        "index_pattern" => "sensor-*",
        "rollup_index" => "sensor_rollup",
        "cron" => "*/30 * * * * ?",
        "page_size" => 1000,
        "groups" => [
            "date_histogram" => [
                "field" => "timestamp",
                "fixed_interval" => "1h",
                "delay" => "7d",
            ],
            "terms" => [
                "fields" => array(
                    "node",
                ),
            ],
        ],
        "metrics" => array(
            [
                "field" => "temperature",
                "metrics" => array(
                    "min",
                    "max",
                    "sum",
                ),
            ],
            [
                "field" => "voltage",
                "metrics" => array(
                    "avg",
                ),
            ],
        ),
    ],
]);
```

#### Ruby

```ruby
response = client.perform_request(
  "PUT",
  "/_rollup/job/sensor",
  {},
  {
    "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"
        ]
      }
    ]
  },
  { "Content-Type": "application/json" },
)
```

## Response Examples

#### Create rollup job response example1

```json
{
  "acknowledged": true
}
```

