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

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 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

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

Hi @s1monw,

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

Thanks for reporting this @Alex_Alexandre

Daniel

Ok thank you :slight_smile:

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

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