# Performance hit when sorting on \_id

**URL:** <https://discuss.elastic.co/t/performance-hit-when-sorting-on--id/3634>\
**Category:** Elasticsearch\
**Created:** [December 6, 2010, 11:51am UTC](https://discuss.elastic.co/t/performance-hit-when-sorting-on--id/3634 "2010-12-06T11:51:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zohar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zohar/32/3245_2.png) [@zohar](https://discuss.elastic.co/u/zohar)\
**Post date:** [December 6, 2010, 11:51am UTC](https://discuss.elastic.co/t/performance-hit-when-sorting-on--id/3634/1 "2010-12-06T11:51:21Z")

</div>

Hi  
We are seeing a massive performance hit ( query goes from 200ms to 1min) for a largish index if we sort on  
\_id. version is 0.11 we are upgrading as I type. We switch the default sort to something else but was wondering if this was expected ?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 6, 2010, 4:29pm UTC](https://discuss.elastic.co/t/performance-hit-when-sorting-on--id/3634/2 "2010-12-06T16:29:42Z")

</div>

The first query when sorting on a field will cause all the field values to be loaded to memory. Since \_id is unique, it has quite a few values, so it takes time to load them. but once its loaded, the next queries will be fast. Also, make sure you are not running into memory problems when doing it.  
On Monday, December 6, 2010 at 1:51 PM, zohar wrote:

> ## Hi We are seeing a massive performance hit ( query goes from 200ms to 1min) for a largish index if we sort on \_id. version is 0.11 we are upgrading as I type. We switch the default sort to something else but was wondering if this was expected ?
> 
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/performance-hit-when-sorting-on-id-tp2026820p2026820.html](http://elasticsearch-users.115913.n3.nabble.com/performance-hit-when-sorting-on-id-tp2026820p2026820.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![zohar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zohar/32/3245_2.png) [@zohar](https://discuss.elastic.co/u/zohar)\
**Post date:** [December 6, 2010, 9:45pm UTC](https://discuss.elastic.co/t/performance-hit-when-sorting-on--id/3634/3 "2010-12-06T21:45:27Z")

</div>

All filed values in the index or all field values matching the query  
or filter?

On Dec 6, 4:29 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> The first query when sorting on a field will cause all the field values to be loaded to memory. Since \_id is unique, it has quite a few values, so it takes time to load them. but once its loaded, the next queries will be fast. Also, make sure you are not running into memory problems when doing it.
> 
> On Monday, December 6, 2010 at 1:51 PM, zohar wrote:
> 
> > ## Hi We are seeing a massive performance hit ( query goes from 200ms to 1min) for a largish index if we sort on \_id. version is 0.11 we are upgrading as I type. We switch the default sort to something else but was wondering if this was expected ?
> > 
> > View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/performance-hit-when-](http://elasticsearch-users.115913.n3.nabble.com/performance-hit-when-)...  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 6, 2010, 10:06pm UTC](https://discuss.elastic.co/t/performance-hit-when-sorting-on--id/3634/4 "2010-12-06T22:06:16Z")

</div>

All field values in the index, thats how sorting works...  
On Monday, December 6, 2010 at 11:45 PM, Zohar wrote:

> All filed values in the index or all field values matching the query  
> or filter?
> 
> On Dec 6, 4:29 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > The first query when sorting on a field will cause all the field values to be loaded to memory. Since \_id is unique, it has quite a few values, so it takes time to load them. but once its loaded, the next queries will be fast. Also, make sure you are not running into memory problems when doing it.
> > 
> > On Monday, December 6, 2010 at 1:51 PM, zohar wrote:
> > 
> > > ## Hi We are seeing a massive performance hit ( query goes from 200ms to 1min) for a largish index if we sort on \_id. version is 0.11 we are upgrading as I type. We switch the default sort to something else but was wondering if this was expected ?
> > > 
> > > View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/performance-hit-when-](http://elasticsearch-users.115913.n3.nabble.com/performance-hit-when-)...  
> > > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![zohar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zohar/32/3245_2.png) [@zohar](https://discuss.elastic.co/u/zohar)\
**Post date:** [December 7, 2010, 10:01pm UTC](https://discuss.elastic.co/t/performance-hit-when-sorting-on--id/3634/5 "2010-12-07T22:01:39Z")

</div>

Ouch. Good to know.  
On Dec 6, 10:06 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> All field values in the index, thats how sorting works...
> 
> On Monday, December 6, 2010 at 11:45 PM, Zohar wrote:
> 
> > All filed values in the index or all field values matching the query  
> > or filter?
> 
> > On Dec 6, 4:29 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > > The first query when sorting on a field will cause all the field values to be loaded to memory. Since \_id is unique, it has quite a few values, so it takes time to load them. but once its loaded, the next queries will be fast. Also, make sure you are not running into memory problems when doing it.
> 
> > > On Monday, December 6, 2010 at 1:51 PM, zohar wrote:
> 
> > > > ## Hi We are seeing a massive performance hit ( query goes from 200ms to 1min) for a largish index if we sort on \_id. version is 0.11 we are upgrading as I type. We switch the default sort to something else but was wondering if this was expected ?
> > > > 
> > > > View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/performance-hit-when-](http://elasticsearch-users.115913.n3.nabble.com/performance-hit-when-)...  
> > > > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 7, 2010, 10:03pm UTC](https://discuss.elastic.co/t/performance-hit-when-sorting-on--id/3634/6 "2010-12-07T22:03:01Z")

</div>

Nothing new for Lucene users..., though I have ideas on how to reduce the memory implications of it.  
On Wednesday, December 8, 2010 at 12:01 AM, Zohar wrote:

> Ouch. Good to know.  
> On Dec 6, 10:06 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > All field values in the index, thats how sorting works...
> > 
> > On Monday, December 6, 2010 at 11:45 PM, Zohar wrote:
> > 
> > > All filed values in the index or all field values matching the query  
> > > or filter?
> > 
> > > On Dec 6, 4:29 pm, Shay Banon wrote:
> > 
> > > > The first query when sorting on a field will cause all the field values to be loaded to memory. Since \_id is unique, it has quite a few values, so it takes time to load them. but once its loaded, the next queries will be fast. Also, make sure you are not running into memory problems when doing it.
> > 
> > > > On Monday, December 6, 2010 at 1:51 PM, zohar wrote:
> > 
> > > > > ## Hi We are seeing a massive performance hit ( query goes from 200ms to 1min) for a largish index if we sort on \_id. version is 0.11 we are upgrading as I type. We switch the default sort to something else but was wondering if this was expected ?
> > > > > 
> > > > > View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/performance-hit-when-](http://elasticsearch-users.115913.n3.nabble.com/performance-hit-when-)...  
> > > > > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).  
> > > > > [.ba...@elasticsearch.com](mailto:.ba...@elasticsearch.com)\>

---

<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, 4:15am UTC](https://discuss.elastic.co/t/performance-hit-when-sorting-on--id/3634/7 "2017-07-06T04:15:36Z")

</div>


