Elastic pipeline calculate value for field

I'm trying to calculate the time value inside elastic pipeline and set this value for field. I need something like this :
curl -X PUT "localhost:9200/_ingest/pipeline/time-pipeline?pretty" -H 'Content-Type: application/json' -d'
{
"description" : "My optional pipeline description",
"processors" : [
{
"set" : {
"description" : "My optional processor description",
"field": "end_time",
"value":"script": {
"source": "doc['@timestamp'].value - 30s",
}
,
},

}

]
}
'
Does anyone know how to do it?

The @timestamp value is just a string and needs to be converted to a ZonedDateTime object so you can substract a time unit from it.

POST _ingest/pipeline/_simulate
{
  "docs": [
    {
      "_source": {
        "@timestamp": "2021-09-13T12:34:56.789Z"
      }
    }
  ],
  "pipeline": {
    "processors": [
      {
        "script": {
          "source": "ctx.new = ZonedDateTime.parse(ctx['@timestamp']).minusSeconds(30);"
        }
      }
    ]
  }
}

Thank you for your response! How can I do it if I want tp subtract seconds from current time, now pre-defined?

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