Unfortunately there is no way to share anything across invocations (per document) in a scoring script.
Also, note that that your example can be done much more simply with the java time api. Here I used an existing ISO format, but you could also use DateTimeFormatter.ofPattern('dd-M-yyyy hh:mm:ss') to get your exact format if it is important.
Instant time = Instant.ofEpochMill(doc.born.value.millis).plus(Duration.ofDays(5));
return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(time);
storing the following script
SimpleDateFormat sdf = new SimpleDateFormat('dd-M-yyyy hh:mm:ss');
and reading as params ?
i am getting the following exception
"lang": "painless",
"caused_by": {
"type": "class_cast_exception",
"reason": "java.util.HashMap cannot be cast to java.text.SimpleDateFormat"
}
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.