简体   繁体   English

Nifi 的震动规格

[英]Jolt Spec for Nifi

I am new to nifi.我是 nifi 的新手。 I was trying to create a jolt spec but not getting it.我试图创建一个震动规范,但没有得到它。 Could anyone please help me.任何人都可以帮助我。

Details as below: The Attributes in flow file : details, id, name , address, status详细信息如下: 流文件中的属性:详细信息、id、名称、地址、状态

Flow file looks like : [{"to": "xxx1"},{"to": "xxx2"},{"to": "xxx3"},{"to": "xxxn"}]流文件看起来像:[{“to”:“xxx1”},{“to”:“xxx2”},{“to”:“xxx3”},{“to”:“xxxn”}]

Expecting below output:期待以下输出:

       { "details": "personal", 
         "home":[
                  {"mobileno": "xxx1",
                   "id": "1",
                   "name" :"bbb",
                   "address": "Address1" },
                  { "mobileno": "xxx2",
                    "id": "2",
                   "name": "aaa",
                   "address": "address2" }
               ],
           "status": "enabled" } 

Am able to develop till this.能够发展到这个程度。 But am not getting how to get "details" field但我不知道如何获得“详细信息”字段

[{
  "operation": "shift",
  "spec": {

    "*": "home",
    "mobileno": "home[0].mobileno"
  }
}, {
  "operation": "default",
  "spec": {
    "status": "${status}",
    "home[]": {
      "*": {
        "name": "${name}",
        "id" : "${id},
        "address": "${address}"
      }
    }
  }
}]

In addition to 7632695's answer, your shift spec won't match "mobileno" on the input, try the following:除了 7632695 的答案外,您的班次规范与输入中的“mobileno”不匹配,请尝试以下操作:

[{
  "operation": "shift",
  "spec": {
    "*": {
      "to": "home[&1].mobileno"
    }
  }
}, {
  "operation": "default",
  "spec": {
    "status": "${status}",
    "details": "${details}",
    "home[]": {
      "*": {
        "name": "${name}",
        "id": "${id}",
        "address": "${address}"
      }
    }
  }
}]

Also, note that for a single flow file, the attributes are constant, so for each entry in the home array, each id, name, and address field will be the same.另请注意,对于单个流文件,属性是恒定的,因此对于 home 数组中的每个条目,每个 id、名称和地址字段都将相同。 From your attributes, how would JOLT know to use id=1 for the first element and id=2 for the second, and so on?根据您的属性,JOLT 怎么知道对第一个元素使用 id=1,对第二个元素使用 id=2,依此类推?

If you want to use the index of the input array as the id, you can add this spec to your chain:如果您想使用输入数组的索引作为 id,您可以将此规范添加到您的链中:

{
    "operation": "shift",
    "spec": {
      "home": {
        "*": {
          "$": "home[&1].id",
          "*": "home[&1].&"
        }
      },
      "*": "&"
    }
}

And if you want them to start at 1 instead of 0, you can add 1 to each of them by adding the following spec to your chain:如果您希望它们从 1 而不是 0 开始,您可以通过将以下规范添加到您的链中来为每个添加 1:

{
  "operation": "modify-overwrite-beta",
  "spec": {
    "home": {
      "*": {
        "id": "=intSum(@0, 1)"
      }
    }
  }
}

In default operation you need to add details attribute.在默认操作中,您需要添加 details 属性。

try with below jolt spec尝试使用以下震动规格

[{
  "operation": "shift",
  "spec": {

    "*": "home",
    "mobileno": "home[0].mobileno"
  }
}, {
  "operation": "default",
  "spec": {
    "status": "${status}",
    "details":"${details}",
    "home[]": {
      "*": {
        "name": "${name}",
        "id": "${id}",
        "address": "${address}"
      }
    }
  }
}]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM