# Atomically create index with single alias

**URL:** <https://discuss.elastic.co/t/atomically-create-index-with-single-alias/18958>\
**Category:** Elasticsearch\
**Created:** [July 29, 2014, 6:20pm UTC](https://discuss.elastic.co/t/atomically-create-index-with-single-alias/18958 "2014-07-29T18:20:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhughes](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@mhughes](https://discuss.elastic.co/u/mhughes)\
**Post date:** [July 29, 2014, 6:20pm UTC](https://discuss.elastic.co/t/atomically-create-index-with-single-alias/18958/1 "2014-07-29T18:20:21Z")

</div>

I have a time-series index. I create a new version once a day using the  
format index-name-YYYY-mm-dd.

When creating the index, I assign it a constant alias of 'index-name'.  
This way, clients can just refer to the 'index-name', and not have to  
append the timestamp. I create the alias when I create the index so it's  
an atomic operation; however I create a new index every day and am  
assigning it the same alias. This is blowing up as you can't have the same  
alias point to multiple indexes. I'm trying to fix this but can't find an  
atomic way to:

1. create the new index
2. remove the alias from the old index
3. add the alias to the new index

I can do 1/3 atomically using the index API or 2/3 atomically using the  
alias API, but I can't find a way to do all three.

Any ideas?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6322f948-6574-45ce-b859-773dbae1f1da%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6322f948-6574-45ce-b859-773dbae1f1da%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [July 29, 2014, 6:57pm UTC](https://discuss.elastic.co/t/atomically-create-index-with-single-alias/18958/2 "2014-07-29T18:57:37Z")

</div>

You can have an alias point to multiple indices. With time-series data,  
this should be a problem since you will not have overlap between the  
different indices. But I think you are correct in that there is no atomic  
way to accomplish all three.

I only search against aliases, so having an index without an alias is  
acceptable since I can accomplish the last 2 steps atomically without  
interfering querying (some data might not be available).

Cheers,

Ivan

On Tue, Jul 29, 2014 at 11:20 AM, Matt Hughes [hughes.matt@gmail.com](mailto:hughes.matt@gmail.com) wrote:

> I have a time-series index. I create a new version once a day using the  
> format index-name-YYYY-mm-dd.
> 
> When creating the index, I assign it a constant alias of 'index-name'.  
> This way, clients can just refer to the 'index-name', and not have to  
> append the timestamp. I create the alias when I create the index so it's  
> an atomic operation; however I create a new index every day and am  
> assigning it the same alias. This is blowing up as you can't have the same  
> alias point to multiple indexes. I'm trying to fix this but can't find an  
> atomic way to:
> 
> 1. create the new index
> 2. remove the alias from the old index
> 3. add the alias to the new index
> 
> I can do 1/3 atomically using the index API or 2/3 atomically using the  
> alias API, but I can't find a way to do all three.
> 
> Any ideas?
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/6322f948-6574-45ce-b859-773dbae1f1da%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6322f948-6574-45ce-b859-773dbae1f1da%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/6322f948-6574-45ce-b859-773dbae1f1da%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/6322f948-6574-45ce-b859-773dbae1f1da%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBRfb37gJ3Ytmg\_kGus-uVNn9h85uvpjG-Et4QM4eZTZw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBRfb37gJ3Ytmg_kGus-uVNn9h85uvpjG-Et4QM4eZTZw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [July 29, 2014, 7:03pm UTC](https://discuss.elastic.co/t/atomically-create-index-with-single-alias/18958/3 "2014-07-29T19:03:59Z")

</div>

I do an atomic alias swap all the time, but I do it after the index is  
created:

curl -XPOST '[http://localhost:9200/\_aliases](http://localhost:9200/_aliases)' -d '  
{  
"actions" : [  
{ "remove" : { "index" : "index1", "alias" : "alias" } },

```
    { "add" : { "index" : "index2", "alias" : "alias" } }

]

```

}'

Nik

On Tue, Jul 29, 2014 at 2:57 PM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> You can have an alias point to multiple indices. With time-series data,  
> this should be a problem since you will not have overlap between the  
> different indices. But I think you are correct in that there is no atomic  
> way to accomplish all three.
> 
> I only search against aliases, so having an index without an alias is  
> acceptable since I can accomplish the last 2 steps atomically without  
> interfering querying (some data might not be available).
> 
> Cheers,
> 
> Ivan
> 
> On Tue, Jul 29, 2014 at 11:20 AM, Matt Hughes [hughes.matt@gmail.com](mailto:hughes.matt@gmail.com)  
> wrote:
> 
> > I have a time-series index. I create a new version once a day using the  
> > format index-name-YYYY-mm-dd.
> > 
> > When creating the index, I assign it a constant alias of 'index-name'.  
> > This way, clients can just refer to the 'index-name', and not have to  
> > append the timestamp. I create the alias when I create the index so it's  
> > an atomic operation; however I create a new index every day and am  
> > assigning it the same alias. This is blowing up as you can't have the same  
> > alias point to multiple indexes. I'm trying to fix this but can't find an  
> > atomic way to:
> > 
> > 1. create the new index
> > 2. remove the alias from the old index
> > 3. add the alias to the new index
> > 
> > I can do 1/3 atomically using the index API or 2/3 atomically using the  
> > alias API, but I can't find a way to do all three.
> > 
> > Any ideas?
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/6322f948-6574-45ce-b859-773dbae1f1da%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6322f948-6574-45ce-b859-773dbae1f1da%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/6322f948-6574-45ce-b859-773dbae1f1da%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/6322f948-6574-45ce-b859-773dbae1f1da%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBRfb37gJ3Ytmg\_kGus-uVNn9h85uvpjG-Et4QM4eZTZw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBRfb37gJ3Ytmg_kGus-uVNn9h85uvpjG-Et4QM4eZTZw%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBRfb37gJ3Ytmg\_kGus-uVNn9h85uvpjG-Et4QM4eZTZw%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBRfb37gJ3Ytmg_kGus-uVNn9h85uvpjG-Et4QM4eZTZw%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAPmjWd1DZMF7QEkokC3nzoFjX8gRqUg\_TXZQy6PVUjZgt9xFFA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd1DZMF7QEkokC3nzoFjX8gRqUg_TXZQy6PVUjZgt9xFFA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [July 29, 2014, 7:06pm UTC](https://discuss.elastic.co/t/atomically-create-index-with-single-alias/18958/4 "2014-07-29T19:06:00Z")

</div>

Typo: With time-series data, this should NOT be a problem

On Tue, Jul 29, 2014 at 11:57 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> You can have an alias point to multiple indices. With time-series data,  
> this should be a problem since you will not have overlap between the  
> different indices. But I think you are correct in that there is no atomic  
> way to accomplish all three.
> 
> I only search against aliases, so having an index without an alias is  
> acceptable since I can accomplish the last 2 steps atomically without  
> interfering querying (some data might not be available).
> 
> Cheers,
> 
> Ivan
> 
> On Tue, Jul 29, 2014 at 11:20 AM, Matt Hughes [hughes.matt@gmail.com](mailto:hughes.matt@gmail.com)  
> wrote:
> 
> > I have a time-series index. I create a new version once a day using the  
> > format index-name-YYYY-mm-dd.
> > 
> > When creating the index, I assign it a constant alias of 'index-name'.  
> > This way, clients can just refer to the 'index-name', and not have to  
> > append the timestamp. I create the alias when I create the index so it's  
> > an atomic operation; however I create a new index every day and am  
> > assigning it the same alias. This is blowing up as you can't have the same  
> > alias point to multiple indexes. I'm trying to fix this but can't find an  
> > atomic way to:
> > 
> > 1. create the new index
> > 2. remove the alias from the old index
> > 3. add the alias to the new index
> > 
> > I can do 1/3 atomically using the index API or 2/3 atomically using the  
> > alias API, but I can't find a way to do all three.
> > 
> > Any ideas?
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/6322f948-6574-45ce-b859-773dbae1f1da%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6322f948-6574-45ce-b859-773dbae1f1da%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/6322f948-6574-45ce-b859-773dbae1f1da%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/6322f948-6574-45ce-b859-773dbae1f1da%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBAk5nvKQvV0XjqM5QvOvD5Ruzsa\_ietuup5a2A-Ks26g%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBAk5nvKQvV0XjqM5QvOvD5Ruzsa_ietuup5a2A-Ks26g%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 1:12am UTC](https://discuss.elastic.co/t/atomically-create-index-with-single-alias/18958/5 "2017-07-06T01:12:26Z")

</div>


