# Query vs. fetch times

**URL:** https://discuss.elastic.co/t/query-vs-fetch-times/13710
**Category:** Elasticsearch
**Created:** [September 20, 2013, 8:22pm UTC](https://discuss.elastic.co/t/query-vs-fetch-times/13710 "2013-09-20T20:22:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Pierce\_Wetter](https://avatars.discourse-cdn.com/v4/letter/p/65b543/32.png) [@Pierce\_Wetter](https://discuss.elastic.co/u/Pierce_Wetter)
#### Post date: [September 20, 2013, 8:22pm UTC](https://discuss.elastic.co/t/query-vs-fetch-times/13710/1 "2013-09-20T20:22:52Z")

</div>

Noob Question:

So my query times in Elastic HQ are about 7x the fetch times.

Is that expected or is it possible we're not giving the shard hint  
correctly so it has to ask all the shards?

--  
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: ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)
#### Post date: [September 20, 2013, 8:46pm UTC](https://discuss.elastic.co/t/query-vs-fetch-times/13710/2 "2013-09-20T20:46:14Z")

</div>

That is expected behavior.

The Search phase has to A) traverse all the shards, B) traverse all  
documents which match your (potentially complex) query and C) calculate a  
score for each matching document. Depending on your query, that is  
potentially a lot of documents to evaluate.

In contrast, the Fetch phase is given a list of document addresses (shard  
and docID). The list is usually small, say ten results. It then goes  
straight to the appropriate shard, loads the document and serializes the  
source back to the coordinating node. This is much faster than the Search  
phase.

As an aside, by default elasticsearch will search all shards of an index.  
You can use custom routing to direct the search to a particular shard, but  
this is generally more advanced behavior and may not be needed.

-Zach

On Friday, September 20, 2013 4:22:52 PM UTC-4, Pierce Wetter wrote:

> Noob Question:
> 
> So my query times in Elastic HQ are about 7x the fetch times.
> 
> Is that expected or is it possible we're not giving the shard hint  
> correctly so it has to ask all the shards?

--  
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: ![Pierce\_Wetter](https://avatars.discourse-cdn.com/v4/letter/p/65b543/32.png) [@Pierce\_Wetter](https://discuss.elastic.co/u/Pierce_Wetter)
#### Post date: [September 20, 2013, 9:49pm UTC](https://discuss.elastic.co/t/query-vs-fetch-times/13710/3 "2013-09-20T21:49:53Z")

</div>

Yeah, I was pretty sure that we were using custom routing, but the  
resulting subset would still be a fair number of documents, so 7x isn't so  
bad from that point of view.

--  
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: ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)
#### Post date: [September 20, 2013, 10:34pm UTC](https://discuss.elastic.co/t/query-vs-fetch-times/13710/4 "2013-09-20T22:34:34Z")

</div>

Ah, I see. Yeah, I'll stand by the original "expected behavior", the  
Search phase will probably be considerably slower than Fetch even if you  
direct it to a single shard, dependent on size of the shard.

Now, if the search is taking too long in general, that's something to be  
concerned about. But I wouldn't worry about search:fetch ratio =)

-Zach

On Fri, Sep 20, 2013 at 5:49 PM, Pierce Wetter [obastard@gmail.com](mailto:obastard@gmail.com) wrote:

> Yeah, I was pretty sure that we were using custom routing, but the  
> resulting subset would still be a fair number of documents, so 7x isn't so  
> bad from that point of view.
> 
> --  
> 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/0tx\_nVTSIxA/unsubscribe](https://groups.google.com/d/topic/elasticsearch/0tx_nVTSIxA/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: ![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:15am UTC](https://discuss.elastic.co/t/query-vs-fetch-times/13710/5 "2017-07-06T02:15:16Z")

</div>


