我有两个XML文件(下面是虚拟版本,实际包含PII),我试图使用MergeRecord合并到一个流文件中。我的流程是获取文件,我使用ExtractText提取父is /DOCID并将其作为属性添加,然后在MergeRecord配置中使用它。我的MergeRecord配置包括一个XML读取器、一个JSON编写器和一个Avro,我已经粘贴在下面。
但是,我的输出是一个流文件,它包含一个JSON数组,而不是一个JSON。这是一个问题,因为我将把它放到Elasticsearch中,如果我将一个流文件放入Elasticsearch,它会将它作为两个单独的条目来处理。我听说过一些关于使用JoltTransform的建议,但我甚至不知道从哪里开始。
输入XML 1
<?xml version="1.0" encoding="UTF-8"?>
<FoundingFathers>
<FatherID>1234</FatherID>
<FatherName>George Washington</FatherName>
<ResidentialInformation>
<Name>Mount Vernon</Name>
<StreetAddress>3200 Mount Vernon Hwy</StreetAddress>
<City>Mt Vernon</City>
<State>VA</State>
<ZipCode>22121</ZipCode>
</ResidentialInformation>
<BirthDate>1732-02-22</BirthDate>
</FoundingFathers>输入XML 2
<?xml version="1.0" encoding="UTF-8"?>
<DOC>
<DOCID>1234</DOCID>
<FATHERNAME>George Washington</FATHERNAME>
<RAW_TXT>George Washington lived in Mount Vernon in Mt Vernon, VA. The Washington family had owned land in the area since 1674. The original house was built in 1734 by Washington's father.</RAW_TXT>
<TXT>
<S>
<FATHERNAME>George Washington</FATHERNAME>
<ESTATENAME>Mount Vernon</>
<ESTATEPLACE>VA</ESTATEPLACE>
</S>
<S>
<OWNER>Washington family</OWNER>
<YEAROWNED>1674</YEAROWNED>
</S>
<S>
<BUILTIN>1734</BUILTIN>
<BUILTBY>Washington's father</BUILTBY>
</S>
</TXT>
</DOC>MergeRecord Configs
Record Reader: XMLReader
Record Writer: JsonRecordSetWriter
Merge Strategy: Bin-Packing Algorithm
Correlation Attribute Name: FatherID
Attribute Strategy: Keep All Unique Attributes
Minimum Number of Records: 2
Maximum Number of Records: 2
Minimum Bin Size: 0 B
Maximum Bin Size: No value set
Max Bin Age: No value set
Maximum Number of Bins: 10模式
{
"namespace": "ff",
"name": "founders",
"type": "record",
"fields": [
{"name":"FatherID", "type": ["string", "null"], "default": null},
{"name":"FatherName", "type": ["string", "null"], "default": null},
{"name":"ResidentialInformation", "type": ["null", {
"name": "ResidentialInformation", "type": "array", "items": {
"name": "ResidentialInformation", "type": "record", "fields": [
{"name": "Name", "type": ["string","null"], "default":null},
{"name": "StreetAddress", "type": ["string","null"], "default":null},
{"name": "City", "type": ["string","null"], "default":null},
{"name": "State", "type": ["string","null"], "default":null},
{"name": "ZipCode", "type": ["string","null"], "default":null}
]
}
}]},
{"name":"BirthDate", "type": ["string", "null"], "default": null},
{"name": "DOCID", "type": ["string", "null"], "default": null},
{"name": "FINAME", "type": ["string", "null"], "default": null},
{"name": "CUSTNAME", "type": {"type": "array", "items": "string"}},
{"name": "RAW_TXT", "type": {"type": "array", "items": "string"}},
{"name": "TXT", "type": {
"name": "TXT", "type": "record", "namespace": "txt.sar", "fields": [
{"name": "S", "type": {
"type": "array", "items": {
"name": "RecordInArray", "type": "record", "fields": [
{"name": "FATHERNAME", "type": {"type": "array", "items": ["string","null"]}},
{"name": "ESTATENAME", "type": {"type": "array", "items": ["string","null"]}},
{"name": "ESTATEPLACE", "type": {"type": "array", "items": ["string","null"]}},
{"name": "OWNER", "type": {"type": "array", "items": ["string","null"]}},
{"name": "YEAROWNED", "type": {"type": "array", "items": ["string","null"]}},
{"name": "BUILTIN", "type": {"type": "array", "items": ["string","null"]}},
{"name": "BUILTBY", "type": {"type": "array", "items": ["string","null"]}}
]
}
}}
]
}}
]}实际输出
[ {
"FatherID" : "1234",
"FatherName" : "George Washington",
"ResidentialInformation" : [ {
"Name" : "Mount Vernon",
"StreetAddress" : "3200 Mount Vernon Hwy",
"City" : "Mt Vernon",
"State" : "VA",
"ZipCode" : "22121"
} ],
"BirthDate" : "1732-02-22",
"DOCID" : null,
"FATHERNAME" : null,
"RAW_TXT" : [ ],
"TXT" : null
}, {
"FatherID" : null,
"FatherName" : null,
"BirthDate" : null,
"DOCID" : "1234",
"FATHERNAME" : "George Washington",
"RAW_TXT" : [ "\nGeorge Washington lived in Mount Vernon in Mt Vernon, VA. The Washington family had owned land in the area since 1674. The original house was built in 1734 by Washington's father.\n" ],
"TXT" : {
"S" : [ {
"FATHERNAME" : [ "George Washington" ],
"ESTATENAME" : [ "Mount Vernon" ],
"ESTATEPLACE" : [ "VA" ]
}, {
"OWNER" : [ "Washington family" ],
"YEAROWNED" : [ "1674" ]
}, {
"BUILTIN" : [ "1734" ],
"BUILTBY" : [ "Washington's father" ]
} ]
}
} ]预期输出
[ {
"FatherID" : "1234",
"FatherName" : "George Washington",
"ResidentialInformation" : [ {
"Name" : "Mount Vernon",
"StreetAddress" : "3200 Mount Vernon Hwy",
"City" : "Mt Vernon",
"State" : "VA",
"ZipCode" : "22121"
} ],
"BirthDate" : "1732-02-22",
"DOCID" : "1234",
"FATHERNAME" : "George Washington",
"RAW_TXT" : [ "\nGeorge Washington lived in Mount Vernon in Mt Vernon, VA. The Washington family had owned land in the area since 1674. The original house was built in 1734 by Washington's father.\n" ],
"TXT" : {
"S" : [ {
"FATHERNAME" : [ "George Washington" ],
"ESTATENAME" : [ "Mount Vernon" ],
"ESTATEPLACE" : [ "VA" ]
}, {
"OWNER" : [ "Washington family" ],
"YEAROWNED" : [ "1674" ]
}, {
"BUILTIN" : [ "1734" ],
"BUILTBY" : [ "Washington's father" ]
} ]
}
} ]发布于 2019-04-22 18:24:35
所需的输出更多的是一个联接,而不是一个合并。合并只是一个接一个地放置记录或内容,在本例中创建一个json数组,其中数组中的每个条目都是作为合并的一部分的每个流文件的json。
处理器并不真正执行真正的流连接,但是在这个答案中描述了一种连接两个JSON流文件的方法:
https://stackoverflow.com/questions/55798982
复制相似问题