i am trying to create visualization of type data table , i want format one of column which shows date in this format Aug 22 10:05:00 2026 GMT , which is string type . i want to format column with condition “if expiry date is less than 7 days, mark as RED. if expiry is less than 30 days and greater than or equal to 7 days , mark as AMBER.“
but problem is field on which i want add condition is string format , which is not supported in formula script ,
and if i try to do using data views from stack management then changes are impacting on complete index
plese suggest solution on this
Hello @mayur_khairnar
Welcome to the Community!!
If the date field is in String than you might need to use a runtime field and based on this field you can have both convert date from string to date format + have the status RED/AMBER/GREEN/EXPIRED as per your requirement.
What is the issue faced by you in below line is not clear :
Reference Runtime field Status Logic :
ZonedDateTime expiry = ZonedDateTime.parse(doc['expiry_date.keyword'].value, DateTimeFormatter.ofPattern('MMM dd HH:mm:ss yyyy z', Locale.ENGLISH));
long millisUntilExpiry = expiry.toInstant().toEpochMilli() - new Date().getTime();
if (millisUntilExpiry < 0) {
emit("EXPIRED");
} else if (millisUntilExpiry < 604800000) {
emit("RED");
} else if (millisUntilExpiry < 2592000000L) {
emit("AMBER");
} else {
emit("GREEN");
}
You can set the format of the field & set the color at time of creation.
Thanks!!