# Can the sorting order of doc\_values arrays be controlled?

**URL:** https://discuss.elastic.co/t/can-the-sorting-order-of-doc-values-arrays-be-controlled/321304
**Category:** Elasticsearch
**Created:** [December 15, 2022, 12:08pm UTC](https://discuss.elastic.co/t/can-the-sorting-order-of-doc-values-arrays-be-controlled/321304 "2022-12-15T12:08:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![David\_Michael\_Gang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_michael_gang/32/114738_2.png) [@David\_Michael\_Gang](https://discuss.elastic.co/u/David_Michael_Gang)
#### Post date: [December 15, 2022, 12:08pm UTC](https://discuss.elastic.co/t/can-the-sorting-order-of-doc-values-arrays-be-controlled/321304/1 "2022-12-15T12:08:01Z")

</div>

As written in the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/doc-values.html)

> Doc values are the on-disk data structure, built at document index time, which makes this data access pattern possible. They store the same values as the `_source` but in a column-oriented fashion that is way more efficient for sorting and aggregations.

I am interested to know in which orderthey are actually stored for each document.

Lets say i have a keyword color and i save a document with the colors [red, green, yellow]

Now i am accessing the keyword color in a script doc["color"]

How do i get the list ? Like i added it [red, green, yellow] ? Do i get it in sorted order ? [green, red, yellow] or is the order non deterministic ?

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [December 18, 2022, 10:33pm UTC](https://discuss.elastic.co/t/can-the-sorting-order-of-doc-values-arrays-be-controlled/321304/2 "2022-12-18T22:33:00Z")

</div>

It's non deterministic because json itself is (not that doc values are stored in json, but it's consistent with the overall approach of Elasticsearch).

---

<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: [January 15, 2023, 10:33pm UTC](https://discuss.elastic.co/t/can-the-sorting-order-of-doc-values-arrays-be-controlled/321304/3 "2023-01-15T22:33:49Z")

</div>

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