首页 > 解决方案 > 如何将自定义属性添加到 AttributesToJSON?

问题描述

我有一个场景,其中文件列表来自前一个处理器,对于每个文件,我必须创建具有流文件属性的 json 文件。在 AttributesToJSON 处理器配置中,有一个提取管道属性的选项,可以创建 json 文件/对象,如果我们将 Include Core Attributes 设置为 true,它将读取一些文件属性并形成 json 文件。 在此处输入图像描述

the out for the above case in my scenario is …
{"fragment.size":"125"
file.group:"root",
file.lastModifiedTime:"2020-12-22T15:09:13+0000",
fragment.identifier:"ee5770ea-8406-400a-a2fd-2362bd706fe0",
fragment.index:"1",
file.creationTime:"2020-12-22T15:09:13+0000",
file.lastAccessTime:"2020-12-22T17:34:22+0000",
segment.original.filename:"Sample-Spreadsheet-10000-rows.csv",
file.owner:"root",
fragment.count:"2",
file.permissions:"rw-r--r--",
text.line.count:"1"}
}



 But the files has other properties, like absolute.path, filename, uuid  are missing in the above json file.
    My requirement is, get the absolute.path, filename and uuid and concatenate absolute.path+/+filename, assign this to custom attribute say filepath:absolute.path+/+filename and also add uuid to json object.  

所以我的 json 文件应该像

{ uuid:"file uuid value", filepath:"absolute.path+/+filename" } 获取上述 json 文件的任何输入。

标签: apache-nifi

解决方案


UpdateAttribute在传递给之前使用处理器删除不必要的属性,AttributestoJSON或者您也可以在attributesToJSON处理器中指定您需要的确切属性。


推荐阅读