# Using doc in script but return in order

**URL:** <https://discuss.elastic.co/t/using-doc-in-script-but-return-in-order/108120>\
**Category:** Elasticsearch\
**Created:** [November 17, 2017, 11:30am UTC](https://discuss.elastic.co/t/using-doc-in-script-but-return-in-order/108120 "2017-11-17T11:30:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Canappeco](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@Canappeco](https://discuss.elastic.co/u/Canappeco)\
**Post date:** [November 17, 2017, 11:30am UTC](https://discuss.elastic.co/t/using-doc-in-script-but-return-in-order/108120/1 "2017-11-17T11:30:18Z")

</div>

Hello all,

I am using `ES 5.6.3`.  
I save some float array in a field named feature, and I want to use them in script.

My mapping:

```auto
"feature" : {
    "type" : "float",
    "index" : false
},

```

But when I use script like `doc['feature']` to get the data, the order change.  
For example, my raw data is

```auto
[0.3, 0.2, 0.1]

```

Now I get

```auto
[0.1, 0.2, 0.3]

```

I don't want to change the order in the field. I know that I can use `_source` to get the raw data, but it is too slow.

Please give me some help. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [November 17, 2017, 5:19pm UTC](https://discuss.elastic.co/t/using-doc-in-script-but-return-in-order/108120/2 "2017-11-17T17:19:20Z")

</div>

docvalues are sorted to allowed improved compression. If you want the original order, you either need to use `_source`, or encode the values into a separate field that you can decode in scripting.

---

<div class="post-metadata">

**Author:** ![Canappeco](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@Canappeco](https://discuss.elastic.co/u/Canappeco)\
**Post date:** [November 19, 2017, 3:41am UTC](https://discuss.elastic.co/t/using-doc-in-script-but-return-in-order/108120/3 "2017-11-19T03:41:51Z")

</div>

Thanks for your response.

However, it is too **slow** to get the raw data using `_source` or saving the in several fields.

Is there any way to prevent es from sorting the docvalues? I heard about that setting `store` to `true` may help, do you have any idea?

Thanks again, may you have a nice day:)

---

<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 17, 2017, 3:54am UTC](https://discuss.elastic.co/t/using-doc-in-script-but-return-in-order/108120/4 "2017-12-17T03:54:30Z")

</div>

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