# Elasticsearch \_aliases usage in Templates?

**URL:** <https://discuss.elastic.co/t/elasticsearch--aliases-usage-in-templates/76656>\
**Category:** Elasticsearch\
**Created:** [February 27, 2017, 4:34pm UTC](https://discuss.elastic.co/t/elasticsearch--aliases-usage-in-templates/76656 "2017-02-27T16:34:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yaswanth](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@Yaswanth](https://discuss.elastic.co/u/Yaswanth)\
**Post date:** [February 27, 2017, 4:34pm UTC](https://discuss.elastic.co/t/elasticsearch--aliases-usage-in-templates/76656/1 "2017-02-27T16:34:29Z")

</div>

Hi

```
   POST /_aliases
    {
        "actions" : [
            { "add" : { "index" : "test*", "alias" : "all_test" } }
        ]
    }

```

1)Based on the above configuration all the indices that start with test and also that are present in the cluster at that point of time will be kept in all\_test alias.

2)If i create alias in Template by using below configuration

```
PUT localhost:9200/_template/test -d '
{
  "template" : "test*",
  "aliases" : {
    "all_test" : {}
  } 
}

```

This will send the future indices which starts with test\* to all\_test alias.

Can i able to do 1+2 = I want to send the existing indices and the future indices to particular alias which i will define in ES Template?

Thanks

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [February 27, 2017, 10:37pm UTC](https://discuss.elastic.co/t/elasticsearch--aliases-usage-in-templates/76656/2 "2017-02-27T22:37:11Z")

</div>

Yes, you can do 1+2 to send the existing indices and the future indices to a particular alias which i will define in ES Template.

---

<div class="post-metadata">

**Author:** ![Yaswanth](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@Yaswanth](https://discuss.elastic.co/u/Yaswanth)\
**Post date:** [February 28, 2017, 2:45am UTC](https://discuss.elastic.co/t/elasticsearch--aliases-usage-in-templates/76656/3 "2017-02-28T02:45:08Z")

</div>

Thanks  
Can you pls provide a sample code for the use case that i had mentioned above?  
So, that i will know how to do that?

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [February 28, 2017, 4:10pm UTC](https://discuss.elastic.co/t/elasticsearch--aliases-usage-in-templates/76656/4 "2017-02-28T16:10:50Z")

</div>

I just use the API call you provided in 1) and 2) . Not sure what sample code you are expecting.

---

<div class="post-metadata">

**Author:** ![Yaswanth](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@Yaswanth](https://discuss.elastic.co/u/Yaswanth)\
**Post date:** [February 28, 2017, 5:11pm UTC](https://discuss.elastic.co/t/elasticsearch--aliases-usage-in-templates/76656/5 "2017-02-28T17:11:08Z")

</div>

Thanks ..

> [@jkuang](#):
>
> I just use the API call you provided in 1) and 2) . Not sure what sample code you are expecting.

That means you are executing 1+2 using api's .

But what i want is can you send the existing indices and future indices to one alias that we define in template?

Through some study i found it out that cant be possible in a template. I have to follow the above 1 and 2 steps.

---

<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:** [March 28, 2017, 5:11pm UTC](https://discuss.elastic.co/t/elasticsearch--aliases-usage-in-templates/76656/6 "2017-03-28T17:11:17Z")

</div>

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