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


(Alex Alexandre) #1

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


(Simon Willnauer) #2

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


(Daniel Mitterdorfer) #3

Hi @s1monw,

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

Thanks for reporting this @Alex_Alexandre

Daniel


(Alex Alexandre) #4

Ok thank you :slight_smile:


(Colin Goodheart-Smithe) #5

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


(Daniel Mitterdorfer) #6

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


(system) #7