How to calculate elapsed Time between Timestamps in a given Timerange?

Hallo fellow Users.

I would like to know how i can get the Time difference from the "First" to the"Last" Document within a specific Time Range.

Question: How much distance did i travel in a specific Time Range.

Situation (Aviation Data) :

Dokument has @Timestamp, Speed, and Altitude, Location

I want to know the covered Distance = Average Speed * Time interval (e.g. last 5 hours).

Displayed in the Dashboard and Canvas via a Visualisation would be appreciated

Data is ingested via Filebeat into Elastic Cloud Service.

My Idea:
(Max.@Timerange - Min.@Timestamp) * Avergage Speed

but How =)

Thanks in advance!

Hi there, this is a case for TSVB bucket scripting. Here's the similar (bur reverse) example. In kibana_sample_data_flight we have available Distance field so I am gonna calculate average speed per hour:

In your case the script will be something like params.averageSpeed * (params._interval/1000/60/60)
The params._interval is passed as ms so we need to convert it to an hour with /1000/60/60 or just 3600000.

Thank you very much @Marta_Bondyra for your Help!
It was really helpful and i took some time to fiddle with the TSVB hence i reply this late.

I have one more "Problem", that you might have a answer to.

My Data is from a Flight Tracker Website (CSV) and the Airplane in Question is not tracked 100% of the Flight. Most of the Time i get the Takeoff and Landing within the Data but missing on several hours of the Flight.

To get the Total Flighttime i am thinking of somehow extracting the first and last Entry in the CSV and calculate the "Total Time".

My approach would be either:

  • Scriped Processor within a Pipeline
  • Runtime Field

Your approach is totally working, no doubt, but for my missing Data it gives me trouble.

1h Interval --> Average Speed = Distance Traveld
Cumulative Sum of Dinstance remains zero if no metrics are recieved.

Kinds regards