# Routing and prepareGet

**URL:** <https://discuss.elastic.co/t/routing-and-prepareget/13216>\
**Category:** Elasticsearch\
**Created:** [August 14, 2013, 6:49pm UTC](https://discuss.elastic.co/t/routing-and-prepareget/13216 "2013-08-14T18:49:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amir\_Raminfar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amir_raminfar/32/2268_2.png) [@Amir\_Raminfar](https://discuss.elastic.co/u/Amir_Raminfar)\
**Post date:** [August 14, 2013, 6:49pm UTC](https://discuss.elastic.co/t/routing-and-prepareget/13216/1 "2013-08-14T18:49:17Z")

</div>

I am in the process of adding routing to my documents to decrease CPU  
usage. I think routing is a great solution. If I understand correctly, I  
can provide the routes that I want to search. If I do not provide the  
routes then it will search across ALL shards. So far that's what my tests  
show.

However, now I want to search by id which is auto generated by ES and I use  
prepareGet. My tests fail when I don't provide the routing. I don't have  
enough data to know the routing when fetching by ID. I was hoping the  
behavior would be the same as search - i.e. if I don't provide the routes  
then it will get across all shards.

Interestingly, prepareMultiGet does this exactly. If I don't provide  
routing then it will return the document to me. Is this "work as designed"?  
Should I use multiGet?

Some code.

// Simple get  
GetResponse response = client().prepareGet(indexName(), documentType(), id).  
execute().get(); // doesn't work

// Multi get  
MultiGetResponse response = client().prepareMultiGet().add(indexName(),documentType  
(), id).execute().get(); // this does work

Any help would be appreciated. Thanks!

--  
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:** ![Amir\_Raminfar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amir_raminfar/32/2268_2.png) [@Amir\_Raminfar](https://discuss.elastic.co/u/Amir_Raminfar)\
**Post date:** [August 14, 2013, 6:51pm UTC](https://discuss.elastic.co/t/routing-and-prepareget/13216/2 "2013-08-14T18:51:54Z")

</div>

Nope I was wrong. MultiGet also doesn't behave this way.

So am I left with doing search even for a simple id?

On Wednesday, August 14, 2013 11:49:17 AM UTC-7, Amir Raminfar wrote:

> I am in the process of adding routing to my documents to decrease CPU  
> usage. I think routing is a great solution. If I understand correctly, I  
> can provide the routes that I want to search. If I do not provide the  
> routes then it will search across ALL shards. So far that's what my tests  
> show.
> 
> However, now I want to search by id which is auto generated by ES and I  
> use prepareGet. My tests fail when I don't provide the routing. I don't  
> have enough data to know the routing when fetching by ID. I was hoping the  
> behavior would be the same as search - i.e. if I don't provide the routes  
> then it will get across all shards.
> 
> Interestingly, prepareMultiGet does this exactly. If I don't provide  
> routing then it will return the document to me. Is this "work as designed"?  
> Should I use multiGet?
> 
> Some code.
> 
> // Simple get  
> GetResponse response = client().prepareGet(indexName(), documentType(), id  
> ).execute().get(); // doesn't work
> 
> // Multi get  
> MultiGetResponse response = client().prepareMultiGet().add(indexName(),documentType  
> (), id).execute().get(); // this does work
> 
> Any help would be appreciated. Thanks!

--  
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:** ![mattweber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattweber/32/44940_2.png) [@mattweber](https://discuss.elastic.co/u/mattweber)\
**Post date:** [August 14, 2013, 7:16pm UTC](https://discuss.elastic.co/t/routing-and-prepareget/13216/3 "2013-08-14T19:16:10Z")

</div>

If you don't have the routing information, then yes, you would need to do a  
search. Why even use routing if you don't know the routing information  
when doing a search/get? If you don't use routing elasticsearch will be  
able to go directly to the correct shard when doing the Get.

Thanks,  
Matt Weber

On Wed, Aug 14, 2013 at 11:51 AM, Amir Raminfar [findamir@gmail.com](mailto:findamir@gmail.com) wrote:

> Nope I was wrong. MultiGet also doesn't behave this way.
> 
> So am I left with doing search even for a simple id?
> 
> On Wednesday, August 14, 2013 11:49:17 AM UTC-7, Amir Raminfar wrote:
> 
> > I am in the process of adding routing to my documents to decrease CPU  
> > usage. I think routing is a great solution. If I understand correctly, I  
> > can provide the routes that I want to search. If I do not provide the  
> > routes then it will search across ALL shards. So far that's what my tests  
> > show.
> > 
> > However, now I want to search by id which is auto generated by ES and I  
> > use prepareGet. My tests fail when I don't provide the routing. I don't  
> > have enough data to know the routing when fetching by ID. I was hoping the  
> > behavior would be the same as search - i.e. if I don't provide the routes  
> > then it will get across all shards.
> > 
> > Interestingly, prepareMultiGet does this exactly. If I don't provide  
> > routing then it will return the document to me. Is this "work as designed"?  
> > Should I use multiGet?
> > 
> > Some code.
> > 
> > // Simple get  
> > GetResponse response = client().prepareGet(indexName(\*\*), documentType(),id  
> > ).execute().get(); // doesn't work
> > 
> > // Multi get  
> > MultiGetResponse response = client().prepareMultiGet().add\*\*(indexName(),documentType  
> > (), id).execute().get(); // this does work
> > 
> > Any help would be appreciated. Thanks!
> 
> --  
> 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).

--  
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:** ![Amir\_Raminfar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amir_raminfar/32/2268_2.png) [@Amir\_Raminfar](https://discuss.elastic.co/u/Amir_Raminfar)\
**Post date:** [August 14, 2013, 7:18pm UTC](https://discuss.elastic.co/t/routing-and-prepareget/13216/4 "2013-08-14T19:18:23Z")

</div>

Thanks for responding. My primary use case to search by URI which is probably 90% of my requests. The \_id is auto generated and I don't need it at all. I guess I should optimize for the more popular use case which is fetching by one field than \_id.

--  
Amir Raminfar

On Wednesday, August 14, 2013 at 12:16 PM, Matt Weber wrote:

> If you don't have the routing information, then yes, you would need to do a search. Why even use routing if you don't know the routing information when doing a search/get? If you don't use routing elasticsearch will be able to go directly to the correct shard when doing the Get.
> 
> Thanks,  
> Matt Weber
> 
> On Wed, Aug 14, 2013 at 11:51 AM, Amir Raminfar \<[findamir@gmail.com](mailto:findamir@gmail.com) ([mailto:findamir@gmail.com](mailto:findamir@gmail.com))\> wrote:
> 
> > Nope I was wrong. MultiGet also doesn't behave this way.
> > 
> > So am I left with doing search even for a simple id?
> > 
> > On Wednesday, August 14, 2013 11:49:17 AM UTC-7, Amir Raminfar wrote:
> > 
> > > I am in the process of adding routing to my documents to decrease CPU usage. I think routing is a great solution. If I understand correctly, I can provide the routes that I want to search. If I do not provide the routes then it will search across ALL shards. So far that's what my tests show.
> > > 
> > > However, now I want to search by id which is auto generated by ES and I use prepareGet. My tests fail when I don't provide the routing. I don't have enough data to know the routing when fetching by ID. I was hoping the behavior would be the same as search - i.e. if I don't provide the routes then it will get across all shards.
> > > 
> > > Interestingly, prepareMultiGet does this exactly. If I don't provide routing then it will return the document to me. Is this "work as designed"? Should I use multiGet?
> > > 
> > > Some code.
> > > 
> > > // Simple get  
> > > GetResponse response = client().prepareGet(indexName(), documentType(), id).execute().get(); // doesn't work
> > > 
> > > // Multi get  
> > > MultiGetResponse response = client().prepareMultiGet().add(indexName(), documentType(), id).execute().get(); // this does work
> > > 
> > > Any help would be appreciated. Thanks!
> > 
> > --  
> > 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) (mailto: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 a topic in the Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/yCjswevglUQ/unsubscribe](https://groups.google.com/d/topic/elasticsearch/yCjswevglUQ/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com) ([mailto: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:** ![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:21am UTC](https://discuss.elastic.co/t/routing-and-prepareget/13216/5 "2017-07-06T02:21:08Z")

</div>


