# ES 5.0-rc1 Sorting by script "... prevent cachability are disabled ..." problem

**URL:** <https://discuss.elastic.co/t/es-5-0-rc1-sorting-by-script-prevent-cachability-are-disabled-problem/63298>\
**Category:** Elasticsearch\
**Created:** [October 18, 2016, 1:10pm UTC](https://discuss.elastic.co/t/es-5-0-rc1-sorting-by-script-prevent-cachability-are-disabled-problem/63298 "2016-10-18T13:10:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Alexandre](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@Alex\_Alexandre](https://discuss.elastic.co/u/Alex_Alexandre)\
**Post date:** [October 18, 2016, 1:10pm UTC](https://discuss.elastic.co/t/es-5-0-rc1-sorting-by-script-prevent-cachability-are-disabled-problem/63298/1 "2016-10-18T13:10:27Z")

</div>

Hi,

I'm actually testing the ES 5.0 release candidate and i'm asking myself if it's still possible to sort results by scripting.  
In the 5.0 doc [Sort | Elasticsearch Guide [5.0] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/search-request-sort.html) its says it's possible but when i do that, i have  
"root\_cause" : [  
{  
"type" : "illegal\_argument\_exception",  
"reason" : "features that prevent cachability are disabled on this context"  
}  
]

Here is my test :

> {"from": 0, "size":1,"sort": , "stored\_fields": ["\_type","\_id"], "query":{"bool":{ "must": [{ "match\_all": {} }], "filter": [{"range": {"echeance\_max": { "gte": "0" } } }] } }, "aggs": { "par\_types": { "terms": { "field": "\_type" }, "aggs": { "les\_plus\_proches": { "top\_hits": { "sort": [  
> { "\_script" : {"type" : "number", "script" : {  
> "lang": "painless",  
> "inline": "floor(abs((doc['altitude'].value)-search\_altitude)/10)",  
> "params" : {  
> "search\_altitude" : 200  
> }}, "order" : "asc"} }, {"\_geo\_distance": {"geoloc": {"lat": 39.9173 , "lon": 116.386 }, "order": "asc", "unit": "km" } } ], "size" : 1 } } } } } }

When i remove the script sorting it works :

> {"from": 0, "size":1,"sort": , "stored\_fields": ["\_type","\_id"], "query":{"bool":{ "must": [{ "match\_all": {} }], "filter": [{"range": {"echeance\_max": { "gte": "0" } } }] } }, "aggs": { "par\_types": { "terms": { "field": "\_type" }, "aggs": { "les\_plus\_proches": { "top\_hits": { "sort": [  
> {"\_geo\_distance": {"geoloc": {"lat": 39.9173 , "lon": 116.386 }, "order": "asc", "unit": "km" } } ], "size" : 1 } } } } } }

Do i miss something ?  
Thanks,  
Alex

---

<div class="post-metadata">

**Author:** ![s1monw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/s1monw/32/3637_2.png) [@s1monw](https://discuss.elastic.co/u/s1monw)\
**Post date:** [October 19, 2016, 2:48pm UTC](https://discuss.elastic.co/t/es-5-0-rc1-sorting-by-script-prevent-cachability-are-disabled-problem/63298/2 "2016-10-19T14:48:40Z")

</div>

this is clearly a bug, can you open an issue?

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [October 19, 2016, 2:55pm UTC](https://discuss.elastic.co/t/es-5-0-rc1-sorting-by-script-prevent-cachability-are-disabled-problem/63298/3 "2016-10-19T14:55:56Z")

</div>

Hi @s1monw,

I was just about to create one: [https://github.com/elastic/elasticsearch/issues/21022](https://github.com/elastic/elasticsearch/issues/21022)

Thanks for reporting this @Alex_Alexandre

Daniel

---

<div class="post-metadata">

**Author:** ![Alex\_Alexandre](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@Alex\_Alexandre](https://discuss.elastic.co/u/Alex_Alexandre)\
**Post date:** [October 19, 2016, 4:02pm UTC](https://discuss.elastic.co/t/es-5-0-rc1-sorting-by-script-prevent-cachability-are-disabled-problem/63298/4 "2016-10-19T16:02:51Z")

</div>

Ok thank you 🙂

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [October 19, 2016, 4:53pm UTC](https://discuss.elastic.co/t/es-5-0-rc1-sorting-by-script-prevent-cachability-are-disabled-problem/63298/5 "2016-10-19T16:53:11Z")

</div>

This is fixed by [https://github.com/elastic/elasticsearch/pull/21023](https://github.com/elastic/elasticsearch/pull/21023). @Alex_Alexandre thanks again for raising this

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [October 20, 2016, 6:48am UTC](https://discuss.elastic.co/t/es-5-0-rc1-sorting-by-script-prevent-cachability-are-disabled-problem/63298/6 "2016-10-20T06:48:36Z")

</div>

Hi @Alex_Alexandre,

when the fix is in, please note that you need to reference `search_altitude` in your Painless script as `params.search_altitude`.

Daniel

---

<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, 10:11pm UTC](https://discuss.elastic.co/t/es-5-0-rc1-sorting-by-script-prevent-cachability-are-disabled-problem/63298/7 "2017-07-05T22:11:02Z")

</div>


