首先你必须修复你的多线模式:
codec => multiline { pattern => "^%{NUMBER:method_id}\|%{DATA:method_type}\|<soapenv:Envelope>" negate => true what => previous }
之后您可以使用Wiktor在评论中建议的模式:
(?m)^(?<method_id>\d+)\|(?<method_type>\w+)\|(?<request><soapenv:Envelope>.*?</soapenv:Envelope>)\|(?<response><soapenv:Envelope>.*?</soapenv:Envelope>)
在您的帖子中显示三个日志行的结果 http://grokconstructor.appspot.com :
您的整个配置可能如下所示:
input { file { path => "/opt/test5/practice_new/xml_input.dat" start_position => "beginning" codec => multiline { pattern => "^%{NUMBER:method_id}\|%{DATA:method_type}\|<soapenv:Envelope>" negate => true what => previous } } } filter { grok { match => [ "message", "(?m)^(?<method_id>\d+)\|(?<method_type>\w+)\|(?<request><soapenv:Envelope>.*?</soapenv:Envelope>)\|(?<response><soapenv:Envelope>.*?</soapenv:Envelope>)" ] } } output { elasticsearch { hosts => "http://localhost:9200" index => "xml" } stdout {} }