Painless dates in update script

I'm a bit struggling with creating an update script in painless that would compare two date fields.

Here is what I have so far (the condition is bogus just for syntax testing):

"script" : {
"inline": "if (Instant.parse(ctx._source.logtime).isBefore(Instant.parse(ctx._source.logtime))) { ctx.op = "none" }",

And this works, except that it expects the field to be in a very particular format. The same script fails on other date fields, for example:

"script": "if (Instant.parse(ctx._source.finishtime).isBefore(Instant.parse(ctx._source.logtime))) { ctx.op = "none" }",
"lang": "painless",
"caused_by": {
"type": "date_time_parse_exception",
"reason": "date_time_parse_exception: Text '2017-04-27T10:32:16' could not be parsed at index 19"

Both logtime and finishtime are date fields, but one is of the format yyyy-MM-dd'T'HH:mm:ss while the other is yyyy-MM-dd'T'HH:mm:ss.SSSZZ.

Is there a generic approach for working with dates in a painless update script that would handle both types of date formats?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.