如何解决Logstash中的“尝试向文档添加第二个根元素”解析错误?

时间:2019-11-06 13:23:16

标签: xml logstash config elastic-stack

我从api中获得了以下xml:

<Journey id=1 fpTime="12:33"></Journey>
<Journey id=2 fpTime="14:33"></Journey>

我想分别解析每个“旅程”并将其发送给elasticsearch。 这是我的logstash配置:

input {
  http_poller {
    urls => {

      test2 => {
        method => get
         url => "https://reiseauskunft.bahn.de/bin/stboard.exe/dn?rt=1&input=Stuttgart%20Hauptbahnhof&boardType=dep&L=vs_java3&productsFilter=111110111&start=yes&maxJourneys=20"

     }

    }
     codec => multiline
        {
            pattern => "<Journey"
            negate => true
            what => "previous"
            charset => "ISO-8859-1"
            auto_flush_interval => 1
        }

    request_timeout => 20
    schedule => { cron => "* * * * * UTC"}
    metadata_target => "http_poller_metadata"
  }
}

    filter {
     xml {
        remove_namespaces => true
        source => "message"
        force_array => false
        target => "msg"
        xpath => ["/Journey/@fpTime", "jTime"]
      }
    }

运行logstash时,出现以下xmlParse错误:

:exception=>#<REXML::ParseException: #<RuntimeError: attempted adding second root element to document>Line: 1 Position: 6218

0 个答案:

没有答案