# 2 aliases to 1 index with rollover

**URL:** <https://discuss.elastic.co/t/2-aliases-to-1-index-with-rollover/321313>\
**Category:** Elasticsearch\
**Tags:** ilm-index-lifecycle-management\
**Created:** [December 15, 2022, 1:28pm UTC](https://discuss.elastic.co/t/2-aliases-to-1-index-with-rollover/321313 "2022-12-15T13:28:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![avnere](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@avnere](https://discuss.elastic.co/u/avnere)\
**Post date:** [December 15, 2022, 1:28pm UTC](https://discuss.elastic.co/t/2-aliases-to-1-index-with-rollover/321313/1 "2022-12-15T13:28:25Z")

</div>

Hi,

I want to define two aliases to index with rollover.

I have set the following:

```auto

PUT _ilm/policy/policy1
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "rollover": {
            "max_primary_shard_size": "40gb"
          }
        }
      },
      "delete": {
        "min_age": "7d",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}

```

```auto
POST _aliases
{
  "actions": [
    {
      "add": {
        "index": "index1-2022.10.18-000001",
        "alias": "alias1",
        "is_write_index": true
      }
    },
    {
      "add": {
        "index": "index1-2022.10.18-000001",
        "alias": "alias2"
      }
    }
]
}

```

After rollover is performed and new index created: index1-2022.10.18-000002, I see that only alias1 assigned to it, without alias2.

What need to be done in order that alias2 will be assigned as well to the new index.

Thanks...

---

<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 15, 2022, 1:49pm UTC](https://discuss.elastic.co/t/2-aliases-to-1-index-with-rollover/321313/2 "2022-12-15T13:49:43Z")

</div>

You need to add the second alias using an index template, so when your new index is created, it will get the alias.

---

<div class="post-metadata">

**Author:** ![avnere](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@avnere](https://discuss.elastic.co/u/avnere)\
**Post date:** [December 15, 2022, 2:23pm UTC](https://discuss.elastic.co/t/2-aliases-to-1-index-with-rollover/321313/3 "2022-12-15T14:23:11Z")

</div>

I want to define both.

I have defined in index template alias1. Can't define both.

```auto
PUT /_index_template/index1_template
{
  "version": 1, 
  "index_patterns": [
    "*index1*"
  ],
  "priority": 2,
  "template": {
    "settings": {
      "index.lifecycle.name": "policy1",
      "index.lifecycle.rollover_alias": "alias1",
      "index.lifecycle.parse_origination_date": true,
      "number_of_shards": 1,
      "number_of_replicas": 0,
      "refresh_interval": "30s",
      "index.codec": "best_compression"
    }
  },
  "composed_of":["component_template"]
}

```

---

<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 15, 2022, 2:30pm UTC](https://discuss.elastic.co/t/2-aliases-to-1-index-with-rollover/321313/4 "2022-12-15T14:30:23Z")

</div>

You can, you defined the writing alias, you can define many other read alias as you want.

You need to add an `aliases` block to your template as per defined in the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-template.html#_index_template_with_index_aliases).

Just add this inside the `template` object and after the `settings` object:

```auto
"aliases" : {
        "alias2" : {}
}

```

---

<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 12, 2023, 2:31pm UTC](https://discuss.elastic.co/t/2-aliases-to-1-index-with-rollover/321313/5 "2023-01-12T14:31:04Z")

</div>

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