Calculate total time of a list of documents

Hi

I have some documents with a field called "duration", in the format HH:MM:SS. I would like to calculate the sum of the duration of the documents i have filtered by a date. However, when trying to sum the data, since it is not a numeric field it is not displayed in the field list

What can i do to sum some date fields?

Thanks

Hi @javidr,

I think you could make use of a runtime field for this use case:

  • define a new runtime field as duration_in_seconds which emits the current duration value as seconds number

For instance something like this may work:

emit(
    doc['duration'].value.toInstant().atZone(ZoneOffset.UTC).toEpochSecond()
);
  • as for the runtime field format pick the Duration option and set seconds as input:

This will make you able to perform math with the duration_in_seconds field and the resulting value in the table/visualization will be something like the initial field one.

yeah but it will not be displayed as a HH:MM:SS field. It is, if i have two documents, with 3600 and 3601 seconds, i want to display 02:00:01

Thanks

Choosing the number format you can leverage the Numerals.js formats to have exactly that format:

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