Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

elasticsearch - How to parse multi line XML in logstash?

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 impossible to manually parse files.

My xml looks like:

<ServiceSalesClosed>
   <ErrorLevel>0</ErrorLevel>
   <ErrorMessage/>
   <LaborSaleCustomerPay>50.00</LaborSaleCustomerPay>`
   ... 

In my input I have the config:

codec => multiline
{ 
pattern => "<ServiceSalesClosed.*"
what => next
}

In my filter the following config:

multiline { 
pattern => [""]
what => next
} 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...