# Cache \_source in memory

**URL:** <https://discuss.elastic.co/t/cache--source-in-memory/38387>\
**Category:** Elasticsearch\
**Created:** [January 5, 2016, 9:37am UTC](https://discuss.elastic.co/t/cache--source-in-memory/38387 "2016-01-05T09:37:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumit\_jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sumit_jain/32/5125_2.png) [@sumit\_jain](https://discuss.elastic.co/u/sumit_jain)\
**Post date:** [January 5, 2016, 9:37am UTC](https://discuss.elastic.co/t/cache--source-in-memory/38387/1 "2016-01-05T09:37:45Z")

</div>

I am using \_source in my sort script to sort docs based on complex logic involving multi level nested fields. But accessing \_source from disk for each matched document is performing poorly, giving me ~ 3 sec response times.

Is there any way to improve this by caching the \_source field in memory? I am willing to pay for more memory, in order to improve the latency.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [January 5, 2016, 12:57pm UTC](https://discuss.elastic.co/t/cache--source-in-memory/38387/2 "2016-01-05T12:57:17Z")

</div>

Not that I know of. The source is likely being pulled into memory by the  
OS's page cache but you still have to pay the overhead of getting it into  
the heap as objects every time.

---

<div class="post-metadata">

**Author:** ![sumit\_jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sumit_jain/32/5125_2.png) [@sumit\_jain](https://discuss.elastic.co/u/sumit_jain)\
**Post date:** [January 6, 2016, 7:24pm UTC](https://discuss.elastic.co/t/cache--source-in-memory/38387/3 "2016-01-06T19:24:49Z")

</div>

Why do you think its likely to come from file system cache, does it work like doc value or just because its accessed frequently?

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [January 6, 2016, 7:41pm UTC](https://discuss.elastic.co/t/cache--source-in-memory/38387/4 "2016-01-06T19:41:42Z")

</div>

Just because its accessed frequently. Doc values are the same way but column oriented rather than a serialized blob. They can take up much less space on disk and you tend to access them in order so they are much more friendly to the disk cache than the way source is stored.

---

<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 5, 2017, 11:26pm UTC](https://discuss.elastic.co/t/cache--source-in-memory/38387/5 "2017-07-05T23:26:40Z")

</div>


