Calculate the time that passed between the insertion of one record and another

Hi, I need your help.

I need to calculate the time that passed between the insertion of one record and another.

Example

I insert a record that tells me the creation of a shift, and after x time I enter a new record with the end of a shift. I need to calculate the time that passed between the creation and end of the shift.

@yorman_steven_ladino How were you wanting to visualize this difference?

If possible, I would recommend using a single shift document with a start and stop timestamp, so you could first create the document with the start timestamp when a shift starts, and then update that document later to add a stop timestamp.

POST shifts/_doc/<shift_id>
{
  "start": "2020-03-23T03:04:15"
}

POST shifts/_update/<shift_id>
{
  "stop": "2020-03-23T09:00:00"
}

This is similar to what is described here: How to calculate the timestamp difference between two actions?

Then you could create a scripted field based on the difference between timestamps. There are some examples of doing date math in painless in this blog post if you want to learn more.

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