Json logstash output file

I am new to logstash and I am trying to enter an xml file through it and output a specific formatted JSON file

Here is an xml example

<?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>

and here is my configuration file

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

The output seems to consist of capturing the information I want, but it also outputs a lot of garbage that I don't need. I would like the end result to be like

{"appartment":[
{"id":"675", "reference":"000671"},
{"id":"1221", "reference":"001218"},
{"id":"1222", "reference":"001219"}
]}

How can i do this

+4
source share

All Articles