I want to sort the email content of watcher based on transformed field,consider "HoursDelayed": from example below Any Idea ?
"send_email": {
"transform": {
"script": {
"source": """
long currdate = new Date().getTime();
def documents = ctx.payload.aggregations.file_delay_agg.buckets.stream()
.filter(fact -> (fact.key[2] =='Pyxis MedStation ES System' && (currdate - fact.extractionDateTime.value)/(1000 * 60 * 60) > fact.min_es_file_delay.value) ||
(fact.key[2] =='EMR System' && (currdate - fact.extractionDateTime.value)/(1000 * 60 * 60) > fact.max_admin_file_delay.value))
.map(hit -> [
"key": hit.key_as_string,
"idnName": hit.key[0],
"facilityName": hit.key[1],
"sourcesystem": hit.key[2],
"clientKey": String.format('%.0f', new def[] { hit.key[3]}),
"timeZone": hit.key[4],
"HoursDelayed": String.format('%02d:%02d:%02d', new def[] {((currdate - hit.extractionDateTime.value)/(1000*60*60)).intValue(), ((((currdate - hit.extractionDateTime.value)/1000)% 3600) /60).intValue(), (((currdate - hit.extractionDateTime.value)/1000)% 60).intValue() }) ,
"max_admin_file_delay": String.format('%.0f', new def[] { hit.max_admin_file_delay.value}),
"min_es_file_delay": String.format('%.0f', new def[] { hit.min_es_file_delay.value}),
"lastfiledate": hit.lastfiledate.value,
"ExtractionDate": hit.lastfiledate.value_as_string,
"max_date": hit.max_date.value_as_string,
"min_date": hit.min_date.value_as_string
])
.collect(Collectors.toList());
return documents;
""",
"lang": "painless"
}
},