Unable to calculate duration by 2 dates fields

how about this

DELETE test

PUT test/_doc/1?refresh
{
  "request": {
    "time": "2019-08-04T20:02:15.459Z"
  },
  "response": {
    "time": "2019-08-04T20:04:03.009Z"
  }
}

POST test/_update_by_query
{
    "script" : {
      "lang" : "painless",
    "source": "ctx._source.duration_in_ms = ZonedDateTime.parse(ctx._source.response.time).toInstant().toEpochMilli() - ZonedDateTime.parse(ctx._source.request.time).toInstant().toEpochMilli()"
  }
}

GET test/_doc/1
1 Like