# Pre-Sorted Doc Values

**URL:** https://discuss.elastic.co/t/pre-sorted-doc-values/2603
**Category:** Elasticsearch
**Created:** [June 12, 2015, 8:08pm UTC](https://discuss.elastic.co/t/pre-sorted-doc-values/2603 "2015-06-12T20:08:10Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Harlin\_ES](https://avatars.discourse-cdn.com/v4/letter/h/977dab/32.png) [@Harlin\_ES](https://discuss.elastic.co/u/Harlin_ES)
#### Post date: [June 12, 2015, 8:08pm UTC](https://discuss.elastic.co/t/pre-sorted-doc-values/2603/1 "2015-06-12T20:08:10Z")

</div>

I was looking into Lucene and noticed that it has a SortedDocValues Class. Does anybody know if Elasticsearch's doc\_values are already using this class or if Elastic plans on implementing anything like this in future versions?

Being able to store field data pre-sorted would drastically improve query speed in my use case.

Thanks,  
Harlin

---

<div class="post-metadata">

### Author: ![lisak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lisak/32/618_2.png) [@lisak](https://discuss.elastic.co/u/lisak)
#### Post date: [June 14, 2015, 11:37pm UTC](https://discuss.elastic.co/t/pre-sorted-doc-values/2603/2 "2015-06-14T23:37:53Z")

</div>

That would be an awesome feature. I just found out that sort-scrolling anything with 10+ millions documents (with doc\_values) is basically so slow that doing it doesn't make sense... 30M takes hours and 100M takes hunders of hours. And I don't think that scaling up horizontally or vertically would help...

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [June 15, 2015, 7:25am UTC](https://discuss.elastic.co/t/pre-sorted-doc-values/2603/3 "2015-06-15T07:25:45Z")

</div>

Yes, SortedDocValues/SortedSetDocValues are what elasticsearch is using to store doc values on not\_analyzed string fields.

However I'm not sure it does what you think it does: this class just maps every unique value to an ordinal and then every document to the ordinals of the values that it contains. Which we later use for sorting and aggregations.

I think that the feature you are after is rather index sorting, which is not implemented yet: [https://github.com/elastic/elasticsearch/issues/6720](https://github.com/elastic/elasticsearch/issues/6720)

---

<div class="post-metadata">

### Author: ![lisak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lisak/32/618_2.png) [@lisak](https://discuss.elastic.co/u/lisak)
#### Post date: [June 15, 2015, 5:28pm UTC](https://discuss.elastic.co/t/pre-sorted-doc-values/2603/4 "2015-06-15T17:28:25Z")

</div>

Good point. Btw regarding `doc_values`, is it possible to set `_timestamp` field as `doc_values`? Because sorting on `_timestamp` might be the most frequent use case.

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [June 18, 2015, 12:24pm UTC](https://discuss.elastic.co/t/pre-sorted-doc-values/2603/5 "2015-06-18T12:24:52Z")

</div>

Yes, `_timestamp` supports doc values.

---

<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, 12:06am UTC](https://discuss.elastic.co/t/pre-sorted-doc-values/2603/6 "2017-07-06T00:06:46Z")

</div>


