Logstash输出json文件

时间:2015-08-28 12:26:13

标签: json logstash logstash-configuration

我是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"}
]}

我该怎么做

0 个答案:

没有答案