You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在ElasticSearch中使用KQL格式化通话时长为hh:mm:ss

在ElasticSearch中用KQL计算并格式化通话时长为hh:mm:ss
  • 核心逻辑:format_timespan函数需要毫秒级时间差作为输入,无需像之前那样转成分钟数,所以要去掉除以60000的操作。
  • 正确公式写法:
    format_timespan(last_value(endtime, kql='endtime: *') - last_value(starttime, kql='starttime: *'), 'HH:mm:ss')
    
    其中HH代表24小时制两位小时(用hh则是12小时制),mm为两位分钟,ss为两位秒数。
  • 若时间字段不是日期类型,需先转换再计算:
    format_timespan(last_value(to_date(endtime), kql='endtime: *') - last_value(to_date(starttime), kql='starttime: *'), 'HH:mm:ss')
    
  • 效果验证:比如时间差为3661000毫秒(对应1小时1分1秒),代入公式后会直接输出01:01:01,完全符合hh:mm:ss格式要求。

内容的提问来源于stack exchange,提问作者Sherri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 21:22:32