Reputation: 533
I'm new in elastic and I need work with date in update-by-query script.
I have docs with field expire which is mapped as date.
I try in my script in update-by-query:
SimpleDateFormat expire = new SimpleDateFormat(\"yyyy-MM-dd'T'HH:mm:ss Z\", Locale.getDefault());
long expireTime = expire.parse(ctx._source.expire).getTime();
But there is error: Unparseable date: "2017-07-21T11:19:42+02:00"
Is there a different way, how got date object or UNIX timestamp?
Or is there a way how got mapped formats instead of strings in update-by-query?
Thank you.
Upvotes: 0
Views: 1153
Reputation: 217424
There's some documentation on working with dates in scripts. Just do this and it will work:
long expireTime = ZonedDateTime.parse(ctx._source.expire).toInstant().toEpochMilli()
Upvotes: 1