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

如何在Elastic Pivot Transform中添加处理完成时间字段

Elastic Pivot Transform 添加运行完成时间戳方案
  • 直接用内置元数据字段
    Elastic Transform默认会给目标索引的每条结果文档加上transform._timestamp字段,这个字段记录的就是Transform运行完成的时间戳,完全符合你的需求,不需要额外配置。你可以直接去目标索引里查看,格式是ISO8601标准时间,比如2024-05-20T12:34:56.789Z。

  • 自定义生成完成时间(按需选择)
    如果需要自定义时间格式或者自己控制时间计算逻辑,可以用scripted_metric聚合来实现。在Pivot的聚合配置里加这么一段:

    "aggs": {
      "completion_time": {
        "scripted_metric": {
          "init_script": "state.times = []",
          "map_script": "state.times.add(new Date())",
          "combine_script": "return state.times.max()",
          "reduce_script": "return states.max()"
        }
      }
    }
    

    这个聚合会取处理所有文档时的最晚时间,也就是Transform运行完成的时间,最终会以completion_time字段的形式出现在结果里。

  • 小提示

    • 用内置的transform._timestamp最省心,不需要额外写脚本,而且是Elastic官方维护的字段,稳定性有保障。
    • 如果用自定义脚本,要确保Elastic允许运行脚本(检查script.allowed_types等配置),避免权限报错。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 21:20:24