# Replace index alias when a new index created

**URL:** <https://discuss.elastic.co/t/replace-index-alias-when-a-new-index-created/200990>\
**Category:** Elasticsearch\
**Created:** [September 25, 2019, 8:03am UTC](https://discuss.elastic.co/t/replace-index-alias-when-a-new-index-created/200990 "2019-09-25T08:03:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jetnet](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@jetnet](https://discuss.elastic.co/u/jetnet)\
**Post date:** [September 25, 2019, 8:03am UTC](https://discuss.elastic.co/t/replace-index-alias-when-a-new-index-created/200990/1 "2019-09-25T08:03:34Z")

</div>

hello All,

we create indices based on index templates, where corresponding aliases are configured, e.g.:

```auto
{
  "order": 0,
  "version": 1,
  "index_patterns": [
    "docs-app-*"
  ],
  "aliases": {
    "docs-app" : {}
  },
    "mappings" : {

```

For example, I'm creating an index:

```
PUT docs-app-v1

```

and it'll get the alias `docs-app`.  
Now, I'd like to create a new version of the index:

```
PUT docs-app-v2

```

and I'd like the alias `docs-app` to point to the new one only, instead of pointing to both, which is current behavior.  
Is it possible? If I'm not mistaken, ILM would not help in such case, as there are no age- or size-related conditions.  
Thanks!

---

<div class="post-metadata">

**Author:** ![kley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kley/32/43533_2.png) [@kley](https://discuss.elastic.co/u/kley)\
**Post date:** [September 25, 2019, 9:35am UTC](https://discuss.elastic.co/t/replace-index-alias-when-a-new-index-created/200990/2 "2019-09-25T09:35:57Z")

</div>

Hey!

I guess this is what you are looking for  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html#indices-aliases-api-rename-alias-ex](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html#indices-aliases-api-rename-alias-ex)

```auto
curl -X POST "localhost:9200/_aliases?pretty" -H 'Content-Type: application/json' -d'
{
    "actions" : [
        { "remove" : { "index" : "docs-app-v1", "alias" : "docs-app" } },
        { "add" : { "index" : "docs-app-v2", "alias" : "docs-app" } }
    ]
}
'

```

---

<div class="post-metadata">

**Author:** ![jetnet](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@jetnet](https://discuss.elastic.co/u/jetnet)\
**Post date:** [September 25, 2019, 9:38am UTC](https://discuss.elastic.co/t/replace-index-alias-when-a-new-index-created/200990/3 "2019-09-25T09:38:25Z")

</div>

not really, I'd like the alias to get replaced **automatically** , as soon as a new index, based on the same template, gets created (`docs-app-v2` in the case above).

---

<div class="post-metadata">

**Author:** ![kley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kley/32/43533_2.png) [@kley](https://discuss.elastic.co/u/kley)\
**Post date:** [September 25, 2019, 9:40am UTC](https://discuss.elastic.co/t/replace-index-alias-when-a-new-index-created/200990/4 "2019-09-25T09:40:10Z")

</div>

Oh, hmm... Ok, there I don't know the solution (if there's one) 😕

---

<div class="post-metadata">

**Author:** ![jetnet](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@jetnet](https://discuss.elastic.co/u/jetnet)\
**Post date:** [September 25, 2019, 9:44am UTC](https://discuss.elastic.co/t/replace-index-alias-when-a-new-index-created/200990/5 "2019-09-25T09:44:31Z")

</div>

I thought, there might be a magic parameter for the `aliases` config:

```auto
  "aliases": {
    "docs-app" : { "MAGIC_PARAMETER_replace_existing": true}
  },

```

🙂

---

<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 23, 2019, 9:44am UTC](https://discuss.elastic.co/t/replace-index-alias-when-a-new-index-created/200990/6 "2019-10-23T09:44:36Z")

</div>

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