# Rollover alias with date does not put the right date

**URL:** https://discuss.elastic.co/t/rollover-alias-with-date-does-not-put-the-right-date/247273
**Category:** Elasticsearch
**Tags:** ilm-index-lifecycle-management
**Created:** [September 2, 2020, 5:34pm UTC](https://discuss.elastic.co/t/rollover-alias-with-date-does-not-put-the-right-date/247273 "2020-09-02T17:34:29Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![pingz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pingz/32/58555_2.png) [@pingz](https://discuss.elastic.co/u/pingz)
#### Post date: [September 2, 2020, 5:34pm UTC](https://discuss.elastic.co/t/rollover-alias-with-date-does-not-put-the-right-date/247273/1 "2020-09-02T17:34:29Z")

</div>

Hi:

I need to have a new index every day with the myindex + datetime (myindex-YYYY.MM.DD).  
I created an index with initial name myindex-2020.09.01-000001.

```auto
  index_body = {
        "aliases": {
           "myindex": {
              "is_write_index": True
           }
        }
 }

```

During the same day on 2020.09.01, I executed the rollover api

```auto
POST /myindex/_rollover 
{
  "conditions": {
    "max_docs": "1"
  }
}

```

A new index was correctly added as myindex-2020.09.01-000002  
However on 2020.09.02, the next day, I expected the new rollover index to be named myindex-2020.09.02-000003. But what I noticed is that the newly created rollover index is named myindex-2020.09.01-000003. The date part of the index name does not correctly match th date when the api was executed.  
I am on Elastic 7.6.1.  
I need help in fixing this rollover alias with date problem.  
Thanks in advance for any help.

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [September 2, 2020, 8:53pm UTC](https://discuss.elastic.co/t/rollover-alias-with-date-does-not-put-the-right-date/247273/2 "2020-09-02T20:53:41Z")

</div>

With ILM, the date in the index name is the date that the policy was first implemented. It does not relate to the date of the index creation. Instead, the counter increases as you are seeing.

---

<div class="post-metadata">

### Author: ![jmceniery](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmceniery/32/54603_2.png) [@jmceniery](https://discuss.elastic.co/u/jmceniery)
#### Post date: [September 2, 2020, 10:14pm UTC](https://discuss.elastic.co/t/rollover-alias-with-date-does-not-put-the-right-date/247273/3 "2020-09-02T22:14:50Z")

</div>

Hi @pingz,

When creating your indices you can use date math instead of creating the index with the actual date.

> [@pingz](#):
>
> myindex-2020.09.01-000001

You would need to create the initial index using date math similar to the below:

```
PUT /%3Cmyindex-%7Bnow%2Fs%7Byyyy-MM-dd-HH-mm-ss%7D%7D-1%3E
{
  "aliases": {
    "roll-alias":{
      "is_write_index": true
    }
  }
}

```

You can read more about that here:

> **[Date math support in system and index alias names | Elasticsearch Guide \[8.11\]...](https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html)**

---

<div class="post-metadata">

### Author: ![jmceniery](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmceniery/32/54603_2.png) [@jmceniery](https://discuss.elastic.co/u/jmceniery)
#### Post date: [September 2, 2020, 10:39pm UTC](https://discuss.elastic.co/t/rollover-alias-with-date-does-not-put-the-right-date/247273/4 "2020-09-02T22:39:34Z")

</div>

Another option which is closer to your example would be:

`PUT /%3Cmyindex-%7Bnow%2Fd%7D-000001%3E`

---

<div class="post-metadata">

### Author: ![pingz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pingz/32/58555_2.png) [@pingz](https://discuss.elastic.co/u/pingz)
#### Post date: [September 3, 2020, 6:37pm UTC](https://discuss.elastic.co/t/rollover-alias-with-date-does-not-put-the-right-date/247273/5 "2020-09-03T18:37:52Z")

</div>

> [@pingz](#):
>
> ```auto
> POST /myindex/_rollover 
> {
> "conditions": {
> "max_docs": "1"
> }
> }
> 
> ```

Thanks John!. Works as expected now.

---

<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: [October 1, 2020, 6:38pm UTC](https://discuss.elastic.co/t/rollover-alias-with-date-does-not-put-the-right-date/247273/6 "2020-10-01T18:38:18Z")

</div>

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