Hi ,
i try to create a new scripted field by calculating the difference(in minutes) between 2 dates in the following format :
bookingStatus.confirmed :Jan 5, 2020 @ 11:30:00.000
bookingStatus.wating :Jan 5, 2020 @ 09:00:00.000
i like the result be like : Xdays ,Xhours, Xminutes
in this case duration = 0 days , 2 hours ,30minutes
i try this expression but i don't get the correct result:
Hi @hiba,
Are your dates saved as date field in Elasticsearch? If so, you can do: doc['bookingStatus.confirmed'].value.millis - doc['bookingStatus.wating'].value.millis will give you the value in miliseconds. If you set the custom format for the field to "Duration" you will also get a nice human readable format for that field.
i get the result by this expression :
def hours = doc['bookingStatus.confirmed'].value.getHour() - doc['bookingStatus.wating'].value.getHour();
def minutes = doc['bookingStatus.confirmed'].value.getMinute() - doc['bookingStatus.wating'].value.getMinute();
def days = doc['bookingStatus.confirmed'].value.dayOfMonth - doc['bookingStatus.wating'].value.dayOfMonth;
return (days+'days,'+hours+'hours,'+minutes+'minutes')
Hi @hiba,
you cannot display it because Kibana doesn't see this value as a duration but as a string and so cannot parse it properly. Did you try the way I suggested? To make it readable, you can set the following options in scripted field panel: type: number Format: Duration InputFormat: seconds (if you use the date fields as normal UNIX timestamp) OutputFormat: Human Readable
for the Difference in milliseconds between two complex datetimes in the link can you please explaine to me how can i use it with this format :
Jan 5, 2020 @ 11:30:00.000
I made an error in the first response, probably that's why it didn't work, sorry! I see in your field list that your fields are of proper type, so it should be working with this configuration:
thank you it work , i have another question please !
i want to calculate the sum of this durations and divide it by the number of bookings in my index.
it very easy to do it with TSVB and use the bucket script . but the TSVB don't support the scripted fields .
how can i do this !
I am afraid at this moment it's not possible in TSVB, unless someone else from the team has an idea? You could possibly use Vega, but it is not a trivial problem. The team is actively working on adding support for scripted fields in TSVB, here's the issue you can upvote: https://github.com/elastic/kibana/issues/13928
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.