# Index rollover due to policy does not copy mapping

**URL:** https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932
**Category:** Elasticsearch
**Tags:** ilm-index-lifecycle-management, rollups
**Created:** [December 8, 2023, 6:05pm UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932 "2023-12-08T18:05:02Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![twilight](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/twilight/32/83450_2.png) [@twilight](https://discuss.elastic.co/u/twilight)
#### Post date: [December 8, 2023, 6:05pm UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/1 "2023-12-08T18:05:02Z")

</div>

Hello,

I have setup an index with a 'date' field in milliseconds (epoch\_millis), I did set this explicitly while creating the index. Then I attached a policy to rollover after x days.

After x days, a new index is created but Kibana is not showing it due to wrong mapping or missing 'date' field. When I checked the new auto created index, it does not have 'date' field mapped as Date.

How can I ensure that the new auto generated indices by the lifecycle policy also copies the same field mappings or atleast the 'date' field from previous or parent index?

Thanks

---

<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: [December 8, 2023, 6:17pm UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/2 "2023-12-08T18:17:43Z")

</div>

You need to specify the mapping through an index template.

---

<div class="post-metadata">

### Author: ![twilight](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/twilight/32/83450_2.png) [@twilight](https://discuss.elastic.co/u/twilight)
#### Post date: [December 8, 2023, 8:20pm UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/3 "2023-12-08T20:20:29Z")

</div>

Thanks for the reply.

Index template for the main/primary index or for the new ones created by the policy? Can you elaborate?  
I have setup an index template but it only allows to set field as Date, how do I specify format which is epoch\_millis in my case?

---

<div class="post-metadata">

### Author: ![abiliocastro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abiliocastro/32/129064_2.png) [@abiliocastro](https://discuss.elastic.co/u/abiliocastro)
#### Post date: [December 8, 2023, 8:46pm UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/4 "2023-12-08T20:46:33Z")

</div>

I think you can create a template like the following:

```auto
{
  "template": {
    "settings": {
      "index": {
        "lifecycle": {
          "name": "your_index_ilm_policy",
          "rollover_alias": "your_index"
        }
      }
    },
    "mappings": {
      "properties": {
        "someDateField": {
          "type": "date",
          "format": "date_optional_time||epoch_millis"
        }
        "anotherField": {
          "type": "keyword"
        }
      }
    },
    "aliases": {}
  }
}

```

And then for every your\_index-00000\* index created by the ilm policy the mapping defined in the template will be applied to the new index

---

<div class="post-metadata">

### Author: ![twilight](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/twilight/32/83450_2.png) [@twilight](https://discuss.elastic.co/u/twilight)
#### Post date: [December 9, 2023, 5:24am UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/5 "2023-12-09T05:24:26Z")

</div>

Thanks, I will try that.  
My goal is to clear old data after X days, can I achieve this within same index without going for rollover or creating new indices?  
I tested the policy without rollover and only setting up delete phase, but it deleted the index itself after the specified time.

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [December 9, 2023, 5:37am UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/6 "2023-12-09T05:37:45Z")

</div>

> [@twilight](#):
>
> My goal is to clear old data after X days, can I achieve this within same index without going for rollover or creating new indices?

Not with ILM, ILM works on entire indices.

To delete data on an index after some specific time you would need to manually execute a `delete_by_query` request.

The best approach is to use ILM with rollover or if you do not want to use the rollover on ILM you would need to create new indices yourself, like daily or monthly indices of example.

---

<div class="post-metadata">

### Author: ![twilight](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/twilight/32/83450_2.png) [@twilight](https://discuss.elastic.co/u/twilight)
#### Post date: [December 9, 2023, 6:18am UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/7 "2023-12-09T06:18:13Z")

</div>

Thanks for the reply.  
If I have an index named index-0001 setup for a rollover after 30 days and that would create index-0002, I have also setup Delete at 7 days.  
When will delete occur and on which index?

If I don't setup Delete and only use Rollover, can I manually delete index-0001 once index-0002 is created and being used for writing?

Thanks

---

<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: [December 9, 2023, 6:46am UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/8 "2023-12-09T06:46:17Z")

</div>

> [@twilight](#):
>
> If I have an index named index-0001 setup for a rollover after 30 days and that would create index-0002, I have also setup Delete at 7 days.

If you are using rollover with ILM the next pahse is based on the rollover date. If your index is set with specific size and max age of 30 days it may rollover after 30 days. If your delete phase is set to 7 days, the index no longer written to will be deleted after an additional 7 days. You will therefore hold up to 37 days worth of data in these indices. Note that if rollover happened earlier due to size the period would be less.

---

<div class="post-metadata">

### Author: ![twilight](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/twilight/32/83450_2.png) [@twilight](https://discuss.elastic.co/u/twilight)
#### Post date: [December 9, 2023, 10:27am UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/9 "2023-12-09T10:27:38Z")

</div>

I defined a template:

```auto
{
  "template": { 
    "settings": {
      "index": {
        "lifecycle": {
          "name": "index-rollover-policy",
          "rollover_alias": "my-index"
        },
        "number_of_replicas":0
      }
    },
    "mappings": {
      "properties": {
        "date": {
          "type": "date",
          "format": "epoch_millis"
        }
      }
    },
    "aliases": {}
  },
  "index_patterns": [
    "my-index"
  ]
}

```

but the index-000001 created by lifecycle policy is still showing date field type as 'text' in the mapping.  
I can push new data to it, it shows doc counts increasing but I can't render the data in Kibana.  
Secondly, as you see I set replica:0 in the template but the new index shows 1 replica while no policy attached to itself.

---

<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: [December 9, 2023, 10:57am UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/10 "2023-12-09T10:57:10Z")

</div>

An index template is only applied when the index is first created, so will not apply to already existing indices. Force a rollover and verify that the index template applies to the new index that was created.

---

<div class="post-metadata">

### Author: ![twilight](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/twilight/32/83450_2.png) [@twilight](https://discuss.elastic.co/u/twilight)
#### Post date: [December 9, 2023, 11:11am UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/11 "2023-12-09T11:11:43Z")

</div>

I understand that, the new index-000001 was created after defining the index-template.  
That is why I am wondering why it didn't get the specified mapping and no policy attached to it?

---

<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: [December 9, 2023, 11:59am UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/12 "2023-12-09T11:59:11Z")

</div>

Does the index pattern specified in the template match the name of the created index?

---

<div class="post-metadata">

### Author: ![twilight](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/twilight/32/83450_2.png) [@twilight](https://discuss.elastic.co/u/twilight)
#### Post date: [December 9, 2023, 12:23pm UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/13 "2023-12-09T12:23:31Z")

</div>

No, the index pattern I thought is the alias which I have for the primary index. IT is without an asterisk \*. I kept it same as rollover-alias.  
Does it need to have a \* in the index-template script so that it applies to every subsequent indices created by the policy?

---

<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: [December 9, 2023, 1:35pm UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/14 "2023-12-09T13:35:53Z")

</div>

If your indices are named e.g. `myindex-000001` and so on, the index pattern must be `myindex-*` so it matches all created indices. It does not matter what the rollover write alias name is.

---

<div class="post-metadata">

### Author: ![twilight](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/twilight/32/83450_2.png) [@twilight](https://discuss.elastic.co/u/twilight)
#### Post date: [December 9, 2023, 1:46pm UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/15 "2023-12-09T13:46:15Z")

</div>

Thanks for reply.  
An observation:  
I created a template with index pattern index-\* and replicas : 0 and mapping for date field. Then I created an index manually with name index-0, it got the mapping and replicas set as 0 from the template, but... Kibana didn't render the date field as regular date time, instead showed a long numeric value (milliseconds) in date column.

---

<div class="post-metadata">

### Author: ![twilight](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/twilight/32/83450_2.png) [@twilight](https://discuss.elastic.co/u/twilight)
#### Post date: [December 9, 2023, 3:18pm UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/16 "2023-12-09T15:18:39Z")

</div>

Setting up an index template with proper mapping, alias and index pattern solved the rollover index 'date' mapping issue. Now I am waiting for auto delete of old index.  
Thank you all!

---

<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: [January 6, 2024, 3:19pm UTC](https://discuss.elastic.co/t/index-rollover-due-to-policy-does-not-copy-mapping/348932/17 "2024-01-06T15:19:08Z")

</div>

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