我是logstash的新手,我正在尝试通过它输入一个xml文件过滤器并输出一个特定格式的JSON文件
这是一个xml的例子
<?xml version="1.0" encoding="UTF-8" ?><apartmentFeed version="1.0" timestamp="20150827:17:19:06">
<apartment id="675">
<general>
<reference>000671</reference>
<name><![CDATA[Brunswick Centre]]>
</name>
</general>
</apartment>
<apartment id="1221">
<general>
<reference>001218</reference>
<name><![CDATA[Saint Luke's]]>
</name>
</general>
</apartment>
<apartment id="1222">
<general>
<reference>001219</reference>
<name><![CDATA[Southwood Abstract]]>
</name>
</general>
</apartment>
</apartmentFeed>
这是我的配置文件
input {
file {
path => "C:/logstash/myXML.xml"
start_position => "beginning"
}
}
filter { multiline {
pattern => "^\s|</apartment>|^[A-Za-z].*"
what => "previous"
}
xml {
store_xml => "false"
source => "message"
xpath => [
"/apartment/@id", "apartment_id",
"/apartment/reference/text()","apartment_txt"
]
}
}
output {
stdout { codec => rubydebug }
file {
codec => "json"
path => ["C:/logstash/temp.json"]
}
}
输出似乎正在捕获我想要的信息,但它也输出了很多我不需要的垃圾。我希望最终输出像
{"appartment":[
{"id":"675", "reference":"000671"},
{"id":"1221", "reference":"001218"},
{"id":"1222", "reference":"001219"}
]}
我怎样才能做到这一点