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.
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"
}
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.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.