How to parse multi line XML in logstash?

后端 未结 1 2017
自闭症患者
自闭症患者 2020-12-19 20:28

I have multiline XML files (~800 lines) in my s3 bucket and i want to index them in Elasticsearch but I can\'t parse them in logstash. Fields are sometimes empty so it\'s im

相关标签:
1条回答
  • 2020-12-19 20:55

    Ok, so it looks like the problem is, you've got confused about your multiline codec and your XML filter.

    Can I suggest you set your multiline up:

    codec => multiline {
         pattern => "<ServiceSalesClosed>" 
         negate => "true"
         what => "previous"
    }
    

    This will take any line that doesn't contain this tag, and keep it with the previous line(s). This should group your XML stanzas into parsable chunks. You should see the results of this in _source.

    Then in your filter:

    filter {
      xml => {
        source => "message"
        target => "xml_content"
        xpath => [ "//ErrorLevel", "error_level" ] 
      }
    }
    

    This should then parse your XML, create fields in the elasticsearch DB for "xml_content" (including your parsed XML) but also specifically extract ErrorLevel into a field of it's own.

    0 讨论(0)
提交回复
热议问题