# Automatically remove older indexes from alias

**URL:** <https://discuss.elastic.co/t/automatically-remove-older-indexes-from-alias/258267>\
**Category:** Elasticsearch\
**Created:** [December 10, 2020, 11:28am UTC](https://discuss.elastic.co/t/automatically-remove-older-indexes-from-alias/258267 "2020-12-10T11:28:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahulkothanath](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahulkothanath/32/99122_2.png) [@rahulkothanath](https://discuss.elastic.co/u/rahulkothanath)\
**Post date:** [December 10, 2020, 11:28am UTC](https://discuss.elastic.co/t/automatically-remove-older-indexes-from-alias/258267/1 "2020-12-10T11:28:44Z")

</div>

I have an elastic search alias named "enrich" and it is defined in index template. How can I remove indices older than 15 days from "enrich" alias automatically?

I am aware of below command but this is manual and I am looking for an automatic solution.  
POST /\_aliases  
{  
"actions" : [  
{ "remove" : { "index" : "test1", "alias" : "enrich" } }  
]  
}

thanks for helping.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 10, 2020, 3:03pm UTC](https://discuss.elastic.co/t/automatically-remove-older-indexes-from-alias/258267/2 "2020-12-10T15:03:34Z")

</div>

I don't think there's a solution out of the box. But if you're naming your indices correctly (with a timestamp for example) that should not be hard for you to write a script which does that.

That being said maybe you can do something with ILM when moving from a hot/warm tier/phase to a cold tier/phase....

---

<div class="post-metadata">

**Author:** ![rahulkothanath](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahulkothanath/32/99122_2.png) [@rahulkothanath](https://discuss.elastic.co/u/rahulkothanath)\
**Post date:** [December 11, 2020, 9:40am UTC](https://discuss.elastic.co/t/automatically-remove-older-indexes-from-alias/258267/3 "2020-12-11T09:40:36Z")

</div>

thanks for the info. I have to keep the index in hot-warm phase and cant move to cold phase . However I will look into the script option to remove index from alias as suggested.

thanks for the help...

---

<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 8, 2021, 9:40am UTC](https://discuss.elastic.co/t/automatically-remove-older-indexes-from-alias/258267/4 "2021-01-08T09:40:55Z")

</div>

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