Math on triggered time in Kibana watcher

I need to get the watcher's triggered time and subtract a random time (e.g. 5mins from it)
I am trying something on the following lines but with no success.
Input:

  "transform": {
    "script": {
      "source": "return [ 'time' : '{{ctx.trigger.triggered_time}}||-5m' ]",
      "lang": "painless"
    }

This literally prints out the string.
Output:

    "transform": {
      "type": "script",
      "status": "success",
      "payload": {
        "time": "{{ctx.trigger.triggered_time}}||-5m"
      }
    },

Isn't transform the right place to do it? Or am I just doing it wrong?
if {{ctx.trigger.triggered_time}} is returned as is (without any math on it), it returns the correct time.
Please assist.

date math is only supported in index names, how about this

    "transform": {
      "script": {
        "source": "return Instant.ofEpochMilli(ctx.trigger.triggered_time.getMillis()).plusSeconds(300)",
        "lang": "painless"
      }
    },

Thanks Alex. Your solution was perfect!
Where can I find the documentation on all these arithmetic functions? Also I am trying to extract substring in my next task. I would appreciate if you could point to some string manipulation functions' documentation as well.

Checking out the painless docs are a good start https://www.elastic.co/guide/en/elasticsearch/reference/6.2/modules-scripting-painless.html

Together with https://github.com/elastic/elasticsearch/tree/master/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi - which allows you to see which methods are available as well.

Hope this helps!

--Alex

Thanks Alex. Much appreciated!

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