# Custom routing and the update API

**URL:** <https://discuss.elastic.co/t/custom-routing-and-the-update-api/15836>\
**Category:** Elasticsearch\
**Created:** [February 16, 2014, 11:11pm UTC](https://discuss.elastic.co/t/custom-routing-and-the-update-api/15836 "2014-02-16T23:11:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Graham\_Bradley](https://avatars.discourse-cdn.com/v4/letter/g/d78d45/32.png) [@Graham\_Bradley](https://discuss.elastic.co/u/Graham_Bradley)\
**Post date:** [February 16, 2014, 11:11pm UTC](https://discuss.elastic.co/t/custom-routing-and-the-update-api/15836/1 "2014-02-16T23:11:47Z")

</div>

Hi, I'm pretty new to ElasticSearch and am starting to look into custom  
routing. I'd like to use my user's usernames as the routing key, as a  
frequent operation will be to find a particular user's content.

I'm sending the routing value along with each indexing call, and this is  
all fine apart from the update API (my application lets users change their  
username, so I need to be able to update all content with a certain  
username). I can specify the routing key in the update call, however this  
obviously finds the document to be updated, rather than letting me update  
the routing.

Is there any way to update a document's routing value without deleting and  
re-indexing manually? I understand that \_update essentially reindexes the  
document anyway, but doing so without resending the entire document would  
be good.

Thanks for any pointers.

--  
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/ddfaa9ec-7b9e-4ede-b2fc-9fd81c85fffc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ddfaa9ec-7b9e-4ede-b2fc-9fd81c85fffc%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [February 17, 2014, 8:35am UTC](https://discuss.elastic.co/t/custom-routing-and-the-update-api/15836/2 "2014-02-17T08:35:10Z")

</div>

Hi Graham,  
being the routing key the way to decide where the document gets indexed,  
you need to delete the original document by specying the old routing key,  
then reindex it with the new one, so that it will get indexed again, but  
this time most likely in a different shard.

By the way, even using the update api with default routing, what happens  
under the hood is a delete + index, just a bit more optimized as it happens  
internally and you make a single http request, but that's exactly how  
lucene works (no update at lucene level).

On Monday, February 17, 2014 12:11:47 AM UTC+1, Graham Bradley wrote:

> Hi, I'm pretty new to Elasticsearch and am starting to look into custom  
> routing. I'd like to use my user's usernames as the routing key, as a  
> frequent operation will be to find a particular user's content.
> 
> I'm sending the routing value along with each indexing call, and this is  
> all fine apart from the update API (my application lets users change their  
> username, so I need to be able to update all content with a certain  
> username). I can specify the routing key in the update call, however this  
> obviously finds the document to be updated, rather than letting me update  
> the routing.
> 
> Is there any way to update a document's routing value without deleting and  
> re-indexing manually? I understand that \_update essentially reindexes the  
> document anyway, but doing so without resending the entire document would  
> be good.
> 
> Thanks for any pointers.

--  
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/55d25dea-3ae2-43c4-8a19-9efa7aaa239f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/55d25dea-3ae2-43c4-8a19-9efa7aaa239f%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Graham\_Bradley](https://avatars.discourse-cdn.com/v4/letter/g/d78d45/32.png) [@Graham\_Bradley](https://discuss.elastic.co/u/Graham_Bradley)\
**Post date:** [February 17, 2014, 9:07am UTC](https://discuss.elastic.co/t/custom-routing-and-the-update-api/15836/3 "2014-02-17T09:07:37Z")

</div>

Hi Luca,

That's what I assumed, thanks for clarifying though. I'll need to decide if  
its less work to occasionally re-index all the user's content, or just use  
the user's (immutable) numeric ID and look this up prior to searching.

Thanks  
Graham

On Monday, February 17, 2014 8:35:10 AM UTC, Luca Cavanna wrote:

> Hi Graham,  
> being the routing key the way to decide where the document gets indexed,  
> you need to delete the original document by specying the old routing key,  
> then reindex it with the new one, so that it will get indexed again, but  
> this time most likely in a different shard.
> 
> By the way, even using the update api with default routing, what happens  
> under the hood is a delete + index, just a bit more optimized as it happens  
> internally and you make a single http request, but that's exactly how  
> lucene works (no update at lucene level).
> 
> On Monday, February 17, 2014 12:11:47 AM UTC+1, Graham Bradley wrote:
> 
> > Hi, I'm pretty new to Elasticsearch and am starting to look into custom  
> > routing. I'd like to use my user's usernames as the routing key, as a  
> > frequent operation will be to find a particular user's content.
> > 
> > I'm sending the routing value along with each indexing call, and this is  
> > all fine apart from the update API (my application lets users change their  
> > username, so I need to be able to update all content with a certain  
> > username). I can specify the routing key in the update call, however this  
> > obviously finds the document to be updated, rather than letting me update  
> > the routing.
> > 
> > Is there any way to update a document's routing value without deleting  
> > and re-indexing manually? I understand that \_update essentially reindexes  
> > the document anyway, but doing so without resending the entire document  
> > would be good.
> > 
> > Thanks for any pointers.

--  
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/71383259-3d5e-41ef-a63a-f40bb6cbed07%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/71383259-3d5e-41ef-a63a-f40bb6cbed07%40googlegroups.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, 1:49am UTC](https://discuss.elastic.co/t/custom-routing-and-the-update-api/15836/4 "2017-07-06T01:49:44Z")

</div>


