# Re-indexing documents while routing has been enabled via multiple aliases

**URL:** <https://discuss.elastic.co/t/re-indexing-documents-while-routing-has-been-enabled-via-multiple-aliases/13259>\
**Category:** Elasticsearch\
**Created:** [August 19, 2013, 6:15pm UTC](https://discuss.elastic.co/t/re-indexing-documents-while-routing-has-been-enabled-via-multiple-aliases/13259 "2013-08-19T18:15:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Melnikov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter_melnikov/32/2150_2.png) [@Peter\_Melnikov](https://discuss.elastic.co/u/Peter_Melnikov)\
**Post date:** [August 19, 2013, 6:15pm UTC](https://discuss.elastic.co/t/re-indexing-documents-while-routing-has-been-enabled-via-multiple-aliases/13259/1 "2013-08-19T18:15:01Z")

</div>

Hi,

I'm looking for the best way to handle model changes in my project. My SaaS  
is going to serve multiple customers and,  
besides the simpler scheme where index is created per customer, I'm  
investigating the other ways to go.

For example, I could use single index with alias for each customer and  
enabled routing (w/o field filter) to ensure the data of the particular  
customer resides in the same shard.  
I've already read an extremely helpful article Changing Mapping With Zero  
Downtime[http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/](http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/) that  
recommends creating new index and coping data into it while the old index is  
still  
accessible via the alias or aliases in my case.

But, how to ensure that data I'm going to re-index will get into the  
customer-specific shards again as they was before, after re-index is done?  
Is it OK to create temporary aliases with the same routing value as the  
original ones for new index, re-index data from each shard, then point old  
aliases to the new index  
while saving the routing settings and delete the temporary aliases and old  
index afterwards? Does it make sense?

Thanks,  
Peter

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [August 19, 2013, 6:46pm UTC](https://discuss.elastic.co/t/re-indexing-documents-while-routing-has-been-enabled-via-multiple-aliases/13259/2 "2013-08-19T18:46:31Z")

</div>

Hey, I think what you say makes sense, the only thing I don't really  
understand is what you mean by:

> But, how to ensure that data I'm going to re-index will get into the  
> customer-specific shards again as they was before, after re-index is done?

can you elaborate on this a bit? I am not understanding the question really.

simon

On Monday, August 19, 2013 8:15:01 PM UTC+2, Peter Melnikov wrote:

> Hi,
> 
> I'm looking for the best way to handle model changes in my project. My  
> SaaS is going to serve multiple customers and,  
> besides the simpler scheme where index is created per customer, I'm  
> investigating the other ways to go.
> 
> For example, I could use single index with alias for each customer and  
> enabled routing (w/o field filter) to ensure the data of the particular  
> customer resides in the same shard.  
> I've already read an extremely helpful article Changing Mapping With Zero  
> Downtime[http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/](http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/) that  
> recommends creating new index and coping data into it while the old index is  
> still  
> accessible via the alias or aliases in my case.
> 
> But, how to ensure that data I'm going to re-index will get into the  
> customer-specific shards again as they was before, after re-index is done?  
> Is it OK to create temporary aliases with the same routing value as the  
> original ones for new index, re-index data from each shard, then point old  
> aliases to the new index  
> while saving the routing settings and delete the temporary aliases and old  
> index afterwards? Does it make sense?
> 
> Thanks,  
> Peter

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Peter\_Melnikov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter_melnikov/32/2150_2.png) [@Peter\_Melnikov](https://discuss.elastic.co/u/Peter_Melnikov)\
**Post date:** [August 19, 2013, 7:25pm UTC](https://discuss.elastic.co/t/re-indexing-documents-while-routing-has-been-enabled-via-multiple-aliases/13259/3 "2013-08-19T19:25:21Z")

</div>

Hi Simon,

Let me make things more clear.  
I have a single index that has multiple shards. I created aliases, say  
customer\_1, customer\_2, customer\_3 and so on.  
These aliases has corresponding routing values for example 1, 2, 3... Thus,  
I ensure that each data associated with specific customer will reside in  
the same shard.  
My application uses these aliases to index and search data for each  
customer, so routing should work without need to specify routing as url  
parameter explicitly.  
Now imagine the situation when something has changed in the model, field  
was deleted or its type has changed. I have no other option as to re-index  
all the data and rebuild entire index.  
Now If I follow the way proposed in the Changing Mapping With Zero Downtime[http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/](http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/) I  
should create new index and then I should copy existing data into it (I'm  
going to use re-index plugin for that). But, if I do not create aliases  
with routing and do not use them while re-indexing, all the client data  
will be mixed in random order across the different shards in new index, so  
I lose customer data locality. The new index a priori is not aware of how  
customer data were distributed before across the shards in the original  
index, and I suppose I have to give it a hint using aliases during the  
re-indexing procedure.

Likely, there is a chance that I missed something important from the  
documentation and articles. So I would be grateful if one pointed me to my  
mistake)

Thanks,  
Peter

On Monday, August 19, 2013 9:46:31 PM UTC+3, simonw wrote:

> Hey, I think what you say makes sense, the only thing I don't really  
> understand is what you mean by:
> 
> > But, how to ensure that data I'm going to re-index will get into the  
> > customer-specific shards again as they was before, after re-index is done?
> 
> can you elaborate on this a bit? I am not understanding the question  
> really.
> 
> simon
> 
> On Monday, August 19, 2013 8:15:01 PM UTC+2, Peter Melnikov wrote:
> 
> > Hi,
> > 
> > I'm looking for the best way to handle model changes in my project. My  
> > SaaS is going to serve multiple customers and,  
> > besides the simpler scheme where index is created per customer, I'm  
> > investigating the other ways to go.
> > 
> > For example, I could use single index with alias for each customer and  
> > enabled routing (w/o field filter) to ensure the data of the particular  
> > customer resides in the same shard.  
> > I've already read an extremely helpful article Changing Mapping With  
> > Zero Downtime[http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/](http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/) that  
> > recommends creating new index and coping data into it while the old  
> > index is still  
> > accessible via the alias or aliases in my case.
> > 
> > But, how to ensure that data I'm going to re-index will get into the  
> > customer-specific shards again as they was before, after re-index is done?  
> > Is it OK to create temporary aliases with the same routing value as the  
> > original ones for new index, re-index data from each shard, then point old  
> > aliases to the new index  
> > while saving the routing settings and delete the temporary aliases and  
> > old index afterwards? Does it make sense?
> > 
> > Thanks,  
> > Peter

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![hitchhikar](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@hitchhikar](https://discuss.elastic.co/u/hitchhikar)\
**Post date:** [August 22, 2013, 1:07pm UTC](https://discuss.elastic.co/t/re-indexing-documents-while-routing-has-been-enabled-via-multiple-aliases/13259/4 "2013-08-22T13:07:49Z")

</div>

While create a new index (say xxx\_v2) cant u specify the \_routing value in  
the type mapping? This value can be same value as you had in alias config  
Have a look at

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Tuesday, August 20, 2013 12:55:21 AM UTC+5:30, Peter Melnikov wrote:

> Hi Simon,
> 
> Let me make things more clear.  
> I have a single index that has multiple shards. I created aliases, say  
> customer\_1, customer\_2, customer\_3 and so on.  
> These aliases has corresponding routing values for example 1, 2, 3...  
> Thus, I ensure that each data associated with specific customer will reside  
> in the same shard.  
> My application uses these aliases to index and search data for each  
> customer, so routing should work without need to specify routing as url  
> parameter explicitly.  
> Now imagine the situation when something has changed in the model, field  
> was deleted or its type has changed. I have no other option as to re-index  
> all the data and rebuild entire index.  
> Now If I follow the way proposed in the Changing Mapping With Zero  
> Downtime[http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/](http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/) I  
> should create new index and then I should copy existing data into it (I'm  
> going to use re-index plugin for that). But, if I do not create aliases  
> with routing and do not use them while re-indexing, all the client data  
> will be mixed in random order across the different shards in new index, so  
> I lose customer data locality. The new index a priori is not aware of how  
> customer data were distributed before across the shards in the original  
> index, and I suppose I have to give it a hint using aliases during the  
> re-indexing procedure.
> 
> Likely, there is a chance that I missed something important from the  
> documentation and articles. So I would be grateful if one pointed me to  
> my mistake)
> 
> Thanks,  
> Peter
> 
> On Monday, August 19, 2013 9:46:31 PM UTC+3, simonw wrote:
> 
> > Hey, I think what you say makes sense, the only thing I don't really  
> > understand is what you mean by:
> > 
> > > But, how to ensure that data I'm going to re-index will get into the  
> > > customer-specific shards again as they was before, after re-index is done?
> > 
> > can you elaborate on this a bit? I am not understanding the question  
> > really.
> > 
> > simon
> > 
> > On Monday, August 19, 2013 8:15:01 PM UTC+2, Peter Melnikov wrote:
> > 
> > > Hi,
> > > 
> > > I'm looking for the best way to handle model changes in my project. My  
> > > SaaS is going to serve multiple customers and,  
> > > besides the simpler scheme where index is created per customer, I'm  
> > > investigating the other ways to go.
> > > 
> > > For example, I could use single index with alias for each customer and  
> > > enabled routing (w/o field filter) to ensure the data of the particular  
> > > customer resides in the same shard.  
> > > I've already read an extremely helpful article Changing Mapping With  
> > > Zero Downtime[http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/](http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/) that  
> > > recommends creating new index and coping data into it while the old  
> > > index is still  
> > > accessible via the alias or aliases in my case.
> > > 
> > > But, how to ensure that data I'm going to re-index will get into the  
> > > customer-specific shards again as they was before, after re-index is done?  
> > > Is it OK to create temporary aliases with the same routing value as the  
> > > original ones for new index, re-index data from each shard, then point old  
> > > aliases to the new index  
> > > while saving the routing settings and delete the temporary aliases and  
> > > old index afterwards? Does it make sense?
> > > 
> > > Thanks,  
> > > Peter

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Peter\_Melnikov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter_melnikov/32/2150_2.png) [@Peter\_Melnikov](https://discuss.elastic.co/u/Peter_Melnikov)\
**Post date:** [August 22, 2013, 2:40pm UTC](https://discuss.elastic.co/t/re-indexing-documents-while-routing-has-been-enabled-via-multiple-aliases/13259/5 "2013-08-22T14:40:32Z")

</div>

Thanks for idea, but for now it is not an option for me as I do not have  
routing field in my data model, would like to try to use alias-level define  
routing first. I'm going to write some tests.

* * *

Best regards,  
Peter Melnikov

Software Engineer  
Axamit Versa, Inc.  
Mobile: +375 29 6747925  
E-mail: [peter@axamit.com](mailto:peter@axamit.com)

2013/8/22 S [reachsonalgupta@gmail.com](mailto:reachsonalgupta@gmail.com)

> While create a new index (say xxx\_v2) cant u specify the \_routing value in  
> the type mapping? This value can be same value as you had in alias config  
> Have a look at  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/routing-field/)
> 
> On Tuesday, August 20, 2013 12:55:21 AM UTC+5:30, Peter Melnikov wrote:
> 
> > Hi Simon,
> > 
> > Let me make things more clear.  
> > I have a single index that has multiple shards. I created aliases, say  
> > customer\_1, customer\_2, customer\_3 and so on.  
> > These aliases has corresponding routing values for example 1, 2, 3...  
> > Thus, I ensure that each data associated with specific customer will reside  
> > in the same shard.  
> > My application uses these aliases to index and search data for each  
> > customer, so routing should work without need to specify routing as url  
> > parameter explicitly.  
> > Now imagine the situation when something has changed in the model, field  
> > was deleted or its type has changed. I have no other option as to re-index  
> > all the data and rebuild entire index.  
> > Now If I follow the way proposed in the Changing Mapping With Zero  
> > Downtime[http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/](http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/) I  
> > should create new index and then I should copy existing data into it (I'm  
> > going to use re-index plugin for that). But, if I do not create aliases  
> > with routing and do not use them while re-indexing, all the client data  
> > will be mixed in random order across the different shards in new index, so  
> > I lose customer data locality. The new index a priori is not aware of how  
> > customer data were distributed before across the shards in the original  
> > index, and I suppose I have to give it a hint using aliases during the  
> > re-indexing procedure.
> > 
> > Likely, there is a chance that I missed something important from the  
> > documentation and articles. So I would be grateful if one pointed me to  
> > my mistake)
> > 
> > Thanks,  
> > Peter
> > 
> > On Monday, August 19, 2013 9:46:31 PM UTC+3, simonw wrote:
> > 
> > > Hey, I think what you say makes sense, the only thing I don't really  
> > > understand is what you mean by:
> > > 
> > > > But, how to ensure that data I'm going to re-index will get into the  
> > > > customer-specific shards again as they was before, after re-index is done?
> > > 
> > > can you elaborate on this a bit? I am not understanding the question  
> > > really.
> > > 
> > > simon
> > > 
> > > On Monday, August 19, 2013 8:15:01 PM UTC+2, Peter Melnikov wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I'm looking for the best way to handle model changes in my project. My  
> > > > SaaS is going to serve multiple customers and,  
> > > > besides the simpler scheme where index is created per customer, I'm  
> > > > investigating the other ways to go.
> > > > 
> > > > For example, I could use single index with alias for each customer and  
> > > > enabled routing (w/o field filter) to ensure the data of the  
> > > > particular customer resides in the same shard.  
> > > > I've already read an extremely helpful article Changing Mapping With  
> > > > Zero Downtime[http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/](http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/) that  
> > > > recommends creating new index and coping data into it while the old  
> > > > index is still  
> > > > accessible via the alias or aliases in my case.
> > > > 
> > > > But, how to ensure that data I'm going to re-index will get into the  
> > > > customer-specific shards again as they was before, after re-index is done?  
> > > > Is it OK to create temporary aliases with the same routing value as the  
> > > > original ones for new index, re-index data from each shard, then point old  
> > > > aliases to the new index  
> > > > while saving the routing settings and delete the temporary aliases and  
> > > > old index afterwards? Does it make sense?
> > > > 
> > > > Thanks,  
> > > > Peter
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to a topic in the  
> > > > Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this topic, visit  
> > > > [https://groups.google.com/d/topic/elasticsearch/3llyLt2I2\_Y/unsubscribe](https://groups.google.com/d/topic/elasticsearch/3llyLt2I2_Y/unsubscribe).  
> > > > To unsubscribe from this group and all its topics, send an email to  
> > > > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![hitchhikar](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@hitchhikar](https://discuss.elastic.co/u/hitchhikar)\
**Post date:** [August 22, 2013, 2:52pm UTC](https://discuss.elastic.co/t/re-indexing-documents-while-routing-has-been-enabled-via-multiple-aliases/13259/6 "2013-08-22T14:52:09Z")

</div>

You can define the same explicit value as u had for alias. It need nt to be  
field in doc

On Thursday, 22 August 2013, Peter Melnikov wrote:

> Thanks for idea, but for now it is not an option for me as I do not have  
> routing field in my data model, would like to try to use alias-level define  
> routing first. I'm going to write some tests.
> 
> * * *
> 
> Best regards,  
> Peter Melnikov
> 
> Software Engineer  
> Axamit Versa, Inc.  
> Mobile: +375 29 6747925  
> E-mail: [peter@axamit.com](mailto:peter@axamit.com) \<javascript:\_e({}, 'cvml', 'peter@axamit.com');\>
> 
> 2013/8/22 S [reachsonalgupta@gmail.com](mailto:reachsonalgupta@gmail.com)
> 
> While create a new index (say xxx\_v2) cant u specify the \_routing value in  
> the type mapping? This value can be same value as you had in alias config  
> Have a look at  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/routing-field/)
> 
> On Tuesday, August 20, 2013 12:55:21 AM UTC+5:30, Peter Melnikov wrote:
> 
> Hi Simon,
> 
> Let me make things more clear.  
> I have a single index that has multiple shards. I created aliases, say  
> customer\_1, customer\_2, customer\_3 and so on.  
> These aliases has corresponding routing values for example 1, 2, 3...  
> Thus, I ensure that each data associated with specific customer will reside  
> in the same shard.  
> My application uses these aliases to index and search data for each  
> customer, so routing should work without need to specify routing as url  
> parameter explicitly.  
> Now imagine the situation when something has changed in the model, field  
> was deleted or its type has changed. I have no other option as to re-index  
> all the data and rebuild entire index.  
> Now If I follow the way proposed in the Changing Mapping With Zero  
> Downtime[http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/](http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/) I  
> should create new index and then I should copy existing data into it (I'm  
> going to use re-index plugin for that). But, if I do not create aliases  
> with routing and do not use them while re-indexing, all the client data  
> will be mixed in random order across the different shards in new index, so  
> I lose customer data locality. The new index a priori is not aware of how  
> customer data were distributed before across the shards in the original  
> index, and I suppose I have to give it a hint using aliases during the  
> re-indexing procedure.
> 
> Likely, there is a chance that I missed something important from the  
> documentation and articles. So I would be grateful if one pointed me to  
> my mistake)
> 
> Thanks,  
> Peter
> 
> On Monday, August 19, 2013 9:46:31 PM UTC+3, simonw wrote:
> 
> Hey, I think what you say makes sense, the only thing I don't really  
> understand is what you mean by:
> 
> > But, how to ensure that data I'm going to re-index will get into the  
> > customer-specific shards again as they was before, after re-index is done?
> 
> can you elaborate on this a bit? I am not understanding the question  
> really.
> 
> simon
> 
> On Monday, August 19, 2013 8:15:01 PM UTC+2, Peter Melnikov wrote:
> 
> Hi,
> 
> I'm looking for the best way to handle model changes in my project. My  
> SaaS is going to serve multiple customers and,  
> besides the simpler scheme where index is created per customer, I'm  
> investigating the other ways to go.
> 
> For example, I could use single index with alias for each customer and  
> enabled routing (w/o field filter) to ensure the data of the particular  
> customer resides in the same shard.  
> I
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/3llyLt2I2\_Y/unsubscribe](https://groups.google.com/d/topic/elasticsearch/3llyLt2I2_Y/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com) \<javascript:\_e({}, 'cvml',  
> 'elasticsearch%2Bunsubscribe@googlegroups.com');\>.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:20am UTC](https://discuss.elastic.co/t/re-indexing-documents-while-routing-has-been-enabled-via-multiple-aliases/13259/7 "2017-07-06T02:20:08Z")

</div>


