# Demystifying Performance- Fast Queries, Slow Scans?

**URL:** <https://discuss.elastic.co/t/demystifying-performance-fast-queries-slow-scans/169467>\
**Category:** Elasticsearch\
**Created:** [February 21, 2019, 5:04pm UTC](https://discuss.elastic.co/t/demystifying-performance-fast-queries-slow-scans/169467 "2019-02-21T17:04:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![micah.williamson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/micah.williamson/32/72718_2.png) [@micah.williamson](https://discuss.elastic.co/u/micah.williamson)\
**Post date:** [February 21, 2019, 5:04pm UTC](https://discuss.elastic.co/t/demystifying-performance-fast-queries-slow-scans/169467/1 "2019-02-21T17:04:06Z")

</div>

I've noticed I can run fairly complex, dynamic count queries and return an exact count over millions of documents. I would assume if searching is so quick, then the only performance bottlenecks for a scan to return the results would be in the network itself.

However, i'm finding scans are extremely cpu intensive operations. I can see from a query that my search applies to ~5mm documents in sub second time (with no noticeable cpu hit), then when I start pulling the data back through the scrolling api, the cpu hits 100% until the scroll is finished.

Could I get some insights into what Elasticsearch does when a scan is happening? Why are queries so easy to perform where scans are very difficult? If I can determine the bottleneck, I can make changes to mitigate those bottlenecks, but I can't make sense/pinpoint where the cpu would be struggling.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 21, 2019, 7:28pm UTC](https://discuss.elastic.co/t/demystifying-performance-fast-queries-slow-scans/169467/2 "2019-02-21T19:28:39Z")

</div>

Aggregations are run based on indexes and generally do not require access to the document source. When you retrieve documents, e.g. through a scroll query, Elasticsearch need to fetch the indexed documents which has the potential to require much more disk I/O and therefore be slower.

---

<div class="post-metadata">

**Author:** ![micah.williamson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/micah.williamson/32/72718_2.png) [@micah.williamson](https://discuss.elastic.co/u/micah.williamson)\
**Post date:** [March 1, 2019, 5:00pm UTC](https://discuss.elastic.co/t/demystifying-performance-fast-queries-slow-scans/169467/3 "2019-03-01T17:00:08Z")

</div>

That must be it. I just wouldn't expect so much CPU work for I/O.

---

<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:** [March 29, 2019, 5:00pm UTC](https://discuss.elastic.co/t/demystifying-performance-fast-queries-slow-scans/169467/4 "2019-03-29T17:00:15Z")

</div>

Closed on March 29, 2019, 5:00pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
