# Rollover by month

**URL:** https://discuss.elastic.co/t/rollover-by-month/107977
**Category:** Elasticsearch
**Created:** [November 16, 2017, 4:00pm UTC](https://discuss.elastic.co/t/rollover-by-month/107977 "2017-11-16T16:00:58Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![acchaulk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/acchaulk/32/24345_2.png) [@acchaulk](https://discuss.elastic.co/u/acchaulk)
#### Post date: [November 16, 2017, 4:00pm UTC](https://discuss.elastic.co/t/rollover-by-month/107977/1 "2017-11-16T16:00:58Z")

</div>

Hello,

I am trying to use the rollover api to help create indexes by month. However, the rollover api does not seem to support months as a max\_age unit: `Failed to parse setting [max_age] with value [1M] as a time value: unit is missing or unrecognized`.

Is there a better approach for achieving indexes by month with the rollover api?

Thanks

---

<div class="post-metadata">

### Author: ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)
#### Post date: [November 16, 2017, 4:41pm UTC](https://discuss.elastic.co/t/rollover-by-month/107977/2 "2017-11-16T16:41:43Z")

</div>

That should work. Can you show your Rollover API call body?

Also, for reference, [using date math with Rollover API](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/indices-rollover-index.html#_using_date_math_with_the_rollover_api).

---

<div class="post-metadata">

### Author: ![acchaulk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/acchaulk/32/24345_2.png) [@acchaulk](https://discuss.elastic.co/u/acchaulk)
#### Post date: [November 16, 2017, 5:08pm UTC](https://discuss.elastic.co/t/rollover-by-month/107977/3 "2017-11-16T17:08:11Z")

</div>

Here is the rollover api body

```json
POST /rollovertest/_rollover?dry_run
{
  "conditions": {
    "max_age": "3M"
  }
}

```

---

<div class="post-metadata">

### Author: ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)
#### Post date: [November 16, 2017, 5:12pm UTC](https://discuss.elastic.co/t/rollover-by-month/107977/4 "2017-11-16T17:12:00Z")

</div>

What indices are behind the alias `rollovertest`?

Since you're doing a `dry_run`, what are the results if you set `max_age` to `90d`?

---

<div class="post-metadata">

### Author: ![acchaulk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/acchaulk/32/24345_2.png) [@acchaulk](https://discuss.elastic.co/u/acchaulk)
#### Post date: [November 16, 2017, 5:50pm UTC](https://discuss.elastic.co/t/rollover-by-month/107977/5 "2017-11-16T17:50:54Z")

</div>

I created a new index with:

```json
PUT /%3Crollovertest-%7Bnow-6M%2Fd%7D-1%3E
{
  "aliases": {
    "rollovertest": {}
  }
}

```

Here are the results of max\_age with 90d:

```json
POST /rollovertest/_rollover?dry_run
{
  "old_index": "rollovertest-2017.05.16-1",
  "new_index": "rollovertest-2017.05.16-000002",
  "rolled_over": false,
  "dry_run": true,
  "acknowledged": false,
  "shards_acknowledged": false,
  "conditions": {
    "[max_age: 90d]": false
  }
}

```

Does max\_age use the index creation date or the date in the index name?

---

<div class="post-metadata">

### Author: ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)
#### Post date: [November 16, 2017, 6:05pm UTC](https://discuss.elastic.co/t/rollover-by-month/107977/6 "2017-11-16T18:05:14Z")

</div>

It uses index `creation_date`.

---

<div class="post-metadata">

### Author: ![acchaulk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/acchaulk/32/24345_2.png) [@acchaulk](https://discuss.elastic.co/u/acchaulk)
#### Post date: [November 16, 2017, 6:08pm UTC](https://discuss.elastic.co/t/rollover-by-month/107977/7 "2017-11-16T18:08:23Z")

</div>

Thats what I thought. Do you have any idea why months do not work for max age?

---

<div class="post-metadata">

### Author: ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)
#### Post date: [November 16, 2017, 6:42pm UTC](https://discuss.elastic.co/t/rollover-by-month/107977/8 "2017-11-16T18:42:21Z")

</div>

I did some asking. It turns out that you need a TimeValue, rather than a DateMath object. [This list](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/common-options.html#time-units) shows the supported units for TimeValues:

- `d` - days
- `h` - hours
- `m` - minutes
- `s` - seconds
- `ms` - milliseconds
- `micros` - microseconds
- `nanos` - nanoseconds

This makes sense, because how would you calculate a month back? The first of the current month? The one before? 30 days ago? The same day of the month for the month previous (e.g. you're on the 30th of March, and there's no 30th of February)?

---

<div class="post-metadata">

### Author: ![acchaulk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/acchaulk/32/24345_2.png) [@acchaulk](https://discuss.elastic.co/u/acchaulk)
#### Post date: [November 16, 2017, 6:55pm UTC](https://discuss.elastic.co/t/rollover-by-month/107977/9 "2017-11-16T18:55:04Z")

</div>

Ah, thanks. I was looking for a list like that but had trouble finding it.. I care about the same month. I will probably take a different approach using the automatic index creation with templates. Thanks for the help!

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [November 16, 2017, 6:59pm UTC](https://discuss.elastic.co/t/rollover-by-month/107977/10 "2017-11-16T18:59:18Z")

</div>

The best thing about rollover is that it supports rolling over based on size or age. If you want completely fixed periods for your indices, sticking with the old and trusted index naming convention might work just as well.

---

<div class="post-metadata">

### Author: ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)
#### Post date: [November 16, 2017, 7:01pm UTC](https://discuss.elastic.co/t/rollover-by-month/107977/11 "2017-11-16T19:01:01Z")

</div>

In that case, you might find what you're looking for with [Elasticsearch Curator](https://www.elastic.co/guide/en/elasticsearch/client/curator/5.4/index.html), specifically the [period filter](https://www.elastic.co/guide/en/elasticsearch/client/curator/5.4/filtertype_period.html). You can combine that with Curator's implementation of the [Rollover](https://www.elastic.co/guide/en/elasticsearch/client/curator/5.4/rollover.html) API, called an action in Curator.

Curator could help you determine the age of an index, and you could use even a `1s` `max_age`, because you'd have vetted the age in the filters already.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [December 14, 2017, 7:01pm UTC](https://discuss.elastic.co/t/rollover-by-month/107977/12 "2017-12-14T19:01:20Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
