AClerk
October 16, 2020, 3:55am
1
Hi,
Some basics in painless (the painful syntax)
Trying to update a filed to have the timestamp value + X hours.
I was trying the following
POST index*/_update_by_query
{
"script": {
"source": "ctx._source.timestamp_shifted = ctx._source.timestamp + 39600",
"lang": "painless"
},
"query": {
"term": {
"msg_source_type_name.keyword": "xxx"
}
}
}
POST index*/_update_by_query
{
"script": {
"source": "ctx._source.timestamp_shifted = ctx._source.timestamp.plusHours(11)",
"lang": "painless"
},
"query": {
"term": {
"msg_source_type_name.keyword": "xxx"
}
}
}
Anyone can point me to the right syntax?
Cheers!
spinscale
(Alexander Reelsen)
October 16, 2020, 2:06pm
2
Hey,
if you access the _source
the field of your date will be a simple string, so you need to parse it as a date first, i.e. using ZonedDateTime.parse()
, and then you can call that .plusHours()
method.
Hope that helps as a start.
--Alex
AClerk
October 19, 2020, 2:49am
3
@spinscale
Thanks for that.
Have an example? Or documentation?
Having syntax issues again.
Cheers!
spinscale
(Alexander Reelsen)
October 19, 2020, 11:15am
4
There is a snippet of local date time parsing in the [examples repo](https://github.com/elastic/examples/blob/master/Alerting/Sample Watches/lateral_movement_in_user_comm/scripts/lower_time.json) that could help you.
system
(system)
Closed
November 16, 2020, 11:15am
5
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.