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

基于引用标识符而非索引的NiFi Jolt值设置需求

NiFi Jolt转换:通过EventCodePrefixId匹配对应Prefix值

正确的Jolt转换规则

[
  {
    "operation": "shift",
    "spec": {
      "EventCodePrefixes": {
        "*": {
          "Prefix": "prefixMap.&1.Prefix",
          "Id": "prefixMap.&1.Id"
        }
      },
      "EventCodes": "EventCodes",
      "EventCodePrefixes": "EventCodePrefixes"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "EventCodes": {
        "*": {
          "EventCodePrefix": "@(3,prefixMap.@(1,EventCodePrefixId).Prefix)"
        }
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "prefixMap": ""
    }
  }
]

规则说明

  1. Shift阶段:将EventCodePrefixes数组转换为以Id为键的prefixMap临时对象,把分散的数组项变成可通过ID直接索引的结构,解决按ID匹配的核心需求。
  2. Modify阶段:遍历EventCodes的每一项,通过@(1,EventCodePrefixId)获取当前项的ID值,再从prefixMap中取出对应的Prefix,赋值给EventCodePrefix字段。@(3,prefixMap...)中的层级索引3用于定位到根节点下的临时映射对象。
  3. Remove阶段:清理临时生成的prefixMap,保证输出结构与原输入一致。

输入示例

{"EventCodes":[{"EventCodePrefixId":2},{"EventCodePrefixId":2}],"EventCodePrefixes":[{"Id":1,"Prefix":"AA"},{"Id":2,"Prefix":"BB"}]}

预期输出

{"EventCodes":[{"EventCodePrefixId":2,"EventCodePrefix":"BB"},{"EventCodePrefixId":2,"EventCodePrefix":"BB"}],"EventCodePrefixes":[{"Id":1,"Prefix":"AA"},{"Id":2,"Prefix":"BB"}]}

原错误规则问题分析

原规则中@(3,EventCodePrefixes[0].Prefix)是硬编码取数组第0项的Prefix,没有根据EventCodePrefixId做动态匹配,导致无论ID是多少都返回AA,无法实现按ID关联的需求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 02:32:47