I am trying to return a date from a painless script and then use that date in the query -> bool -> filter range query. But this does not seem to work.
- How should I access the first element of the newVal array?
- Is the String to Date conversion correct?
GET /index-name/_search
{
"_source": {
"includes": [
"newVal"
]
},
"script_fields": {
"newVal": {
"script": {
"source": """
String lastChangeDate = '2022-08-04 18:22:29.985';
DateTimeFormatter changedDateFormat = DateTimeFormatter.ofPattern('yyyy-MM-dd HH:mm:ss.SSS');
LocalDateTime changedDate = LocalDateTime.parse(lastChangeDate, changedDateFormat);
return changedDate;
"""
}
}
},
"query":
{
"bool":
{
"filter":
[
{"range": { "newVal": {"lte": "now"}}}
]
}
}
}```