We need to use a script to sort the results of a saved search.
One way this can be achieved is with scripted fields, but scripted fields cannot be imported/exported, so it would add a manual step in multiple deployments. Due to this limitation we cannot use scripted fields, we only want to import/export our kibana artifacts and cannot add a manual step to create the scripted field in all deployments.
I can query elasticsearch by providing this sort (natural sorting for a string field containing numeric information):
"sort":
[
{
"_script":{
"script" : {
"inline" : "String rid = doc[\"rid\"].value; if (rid == null || rid.equals(\"\")) return \"\"; else { try {def s_rid = \"\"; StringTokenizer st = new StringTokenizer(rid, \":\"); while (st.hasMoreTokens()) s_rid+=String.format(\"%05d\",new def[] {Integer.parseInt(st.nextToken())}); return s_rid;} catch(Exception e) {return rid}}"
},
"type":"string"
}}
]
In the definition of saved search, when I enter the same script it throws bad data error, and looks like it can only accept fields/scripted fields. I can have the scripted field in the kibanaSavedObjectMeta.searchSourceJSON section to see it in the discover tab, but I am not able to sort by it.
Is there any way to achieve custom sorting in kibana discover tab (or any other visualization which can show tabular data) using script based sorting (and doesn;t require manual steps for scripted field creation)?