Hi,
I'm having a bit of trouble figuring out how to sort using an installed painless script. I installed the script using:
self.connection.put_script(
lang="painless", id="partialNumericSort",
body={"script": self.script_partial_numeric_sort}
)
where self.script_partial_numeric_sort is a property containing the Painless code to be used for sorting.
Putting the script seems to work fine, no compile errors while creating the index.
Though, now I am not sure how to format the self.search().sort(_sort_params_here).execute().
where self.search() returns a elasticsearch_dsl Search object. to utilize this sort script...
In pure JSON format, it would look like:
{
"query": _my_query_goes_here_,
"sort": [{
"_script": {
"lang": "painless",
"order": "asc",
"params": {
"delim": "._",
"fieldName": "seq",
"prefix": "sq"
},
"script_id": "partialNumericSort",
"type": "text"
}]
}
Any help would greatly be appreciated.
If you have complex search params like this you can always just pass them to the sort method:
s = s.sort({
"_script": {
"lang": "painless",
"order": "asc",
"params": {
"delim": "._",
"fieldName": "seq",
"prefix": "sq"
},
"script_id": "partialNumericSort",
"type": "text"
})
Hope this helps!
Most helpful comment
If you have complex search params like this you can always just pass them to the
sortmethod:Hope this helps!