# Sorting memory impact on Elasticsearch

**URL:** <https://discuss.elastic.co/t/sorting-memory-impact-on-elasticsearch/155369>\
**Category:** Elasticsearch\
**Created:** [November 5, 2018, 9:01am UTC](https://discuss.elastic.co/t/sorting-memory-impact-on-elasticsearch/155369 "2018-11-05T09:01:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yashasvi\_Raj\_Pant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yashasvi_raj_pant/32/35022_2.png) [@Yashasvi\_Raj\_Pant](https://discuss.elastic.co/u/Yashasvi_Raj_Pant)\
**Post date:** [November 5, 2018, 9:01am UTC](https://discuss.elastic.co/t/sorting-memory-impact-on-elasticsearch/155369/1 "2018-11-05T09:01:16Z")

</div>

Suppose I have to sort elasticsearch documents by a field "A"(ElasticSearch 2.4.4) as shown here:

[https://www.elastic.co/guide/en/elasticsearch/reference/2.4/search-request-sort.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.4/search-request-sort.html)

i.) Which will consume more memory? High document counts of the type in the index or high cardinality(number of unique count) of the field "A"?

ii.) Which data type of "A" will consume more memory(string, long, date etc.)?

Thanks.

---

<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:** [November 12, 2018, 3:40pm UTC](https://discuss.elastic.co/t/sorting-memory-impact-on-elasticsearch/155369/2 "2018-11-12T15:40:25Z")

</div>

The docs there probably need tweaking a bit. Starting in 2.x (iirc) doc values are enabled by default for all fields except `text` (analyzed string) fields: [https://www.elastic.co/guide/en/elasticsearch/reference/2.4/doc-values.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.4/doc-values.html)

Doc values are disk-based and consume little memory at runtime. So sorting anything except analyzed text fields will use doc values and not consume much memory.

Text fields continue to need in-memory field data for sorting, which can be expensive. In that case, smaller/lower-"cardinality" text fields will consume less memory. E.g. analyzed strings of full text will consume less memory than unique alpha-numeric identifiers.

---

<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:** [December 10, 2018, 3:40pm UTC](https://discuss.elastic.co/t/sorting-memory-impact-on-elasticsearch/155369/3 "2018-12-10T15:40:26Z")

</div>

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