# Automatically apply filtered alias for daily indices

**URL:** <https://discuss.elastic.co/t/automatically-apply-filtered-alias-for-daily-indices/180388>\
**Category:** Elasticsearch\
**Created:** [May 9, 2019, 2:42pm UTC](https://discuss.elastic.co/t/automatically-apply-filtered-alias-for-daily-indices/180388 "2019-05-09T14:42:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![YvorL](https://avatars.discourse-cdn.com/v4/letter/y/9fc348/32.png) [@YvorL](https://discuss.elastic.co/u/YvorL)\
**Post date:** [May 9, 2019, 2:42pm UTC](https://discuss.elastic.co/t/automatically-apply-filtered-alias-for-daily-indices/180388/1 "2019-05-09T14:42:08Z")

</div>

Hi!

I'm currently adding rollup jobs where filtering isn't an option. I have various cases, some would be a simple match for one field (I'd monitor the count), others would require bucketing, cardinality and a final sum aggregation on those. The extent of Elasticsearch's capability and built-in features always amazes me and I learn a new thing every week. Today I stumbled upon filtered aliases. As far as I got it seems, that - without adding an extra tool (e.g., Curator plugin) to the stack - I can't add a "view" for a daily index. I don't want to apply the view for all indices because that'd be a huge waste of resources (one index ~150GB).  
**The question** would be if there's a way in Elasticsearch to automatically add a filtered alias to daily indices?

Thank you!

---

<div class="post-metadata">

**Author:** ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)\
**Post date:** [May 9, 2019, 3:26pm UTC](https://discuss.elastic.co/t/automatically-apply-filtered-alias-for-daily-indices/180388/2 "2019-05-09T15:26:21Z")

</div>

> [@YvorL](#):
>
> [Is there] a way in Elasticsearch to automatically add a filtered alias to daily indices?

You can add a [filtered alias to an index template](https://www.elastic.co/guide/en/elasticsearch/reference/7.0/indices-templates.html#indices-templates). It would be available at index creation time.

```auto
PUT _template/template_1
{
    "index_patterns" : ["te*"],
    "settings" : {
        "number_of_shards" : 1
    },
    "aliases" : {
        "alias1" : {},
        "alias2" : {
            "filter" : {
                "term" : {"user" : "kimchy" }
            },
            "routing" : "kimchy"
        },
        "{index}-alias" : {} 
    }
}

```

Every new index created that matches `index_pattern` will get the filtered alias.

---

<div class="post-metadata">

**Author:** ![YvorL](https://avatars.discourse-cdn.com/v4/letter/y/9fc348/32.png) [@YvorL](https://discuss.elastic.co/u/YvorL)\
**Post date:** [May 9, 2019, 3:39pm UTC](https://discuss.elastic.co/t/automatically-apply-filtered-alias-for-daily-indices/180388/3 "2019-05-09T15:39:00Z")

</div>

Thanks! Will check it in the upcoming days!

Have a great day 🙂!

---

<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:** [June 6, 2019, 3:39pm UTC](https://discuss.elastic.co/t/automatically-apply-filtered-alias-for-daily-indices/180388/4 "2019-06-06T15:39:01Z")

</div>

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