This is done in Painless Lab so will need to change for a scripted field.
# Get the date and store in ZonedDateTime variable.
ZonedDateTime zdt = ZonedDateTime.parse(params.date_field);
# Set the pattern which is day of week. See documentation below.
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("E");
# Extract the day of the week and save as a string.
String day_of_week = zdt.format(formatter);
# Output the day of week.
return day_of_week;
The below should work. Just replace with your field name. The only thing that changes is where you are getting the data from.
# Get the date and store in ZonedDateTime variable.
ZonedDateTime zdt = ZonedDateTime.parse(doc['YOUR-FIELD-NAME'].value);
# Set the pattern which is day of week. See documentation below.
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("E");
# Extract the day of the week and save as a string.
String day_of_week = zdt.format(formatter);
# Output the day of week.
return day_of_week;
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.