I'm running latest ELK stack 6.6 on deviantony/docker-elk image. I have the following XML file which I try to parse into ES JSON object:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<ChainId>7290027600007</ChainId>
<SubChainId>001</SubChainId>
<StoreId>001</StoreId>
<BikoretNo>9</BikoretNo>
<DllVerNo>8.0.1.3</DllVerNo>
</root>
My conf file is:
input {
file {
path => "/usr/share/logstash/logs/example1.xml"
type => "xml"
start_position => "beginning"
sincedb_path => "/dev/null"
codec => multiline {
pattern => "<?xml version"
negate => true
what => "previous"
}
}
}
filter {
xml {
source => "message"
store_xml => false
xpath => [ "/root/ChainId/text()", "ChainId" ]
}
}
output {
elasticsearch {
hosts => "elasticsearch:9200"
index => "xml_index"
manage_template => false
}
}
My Logstash output is:
{ logstash_1 | "@timestamp" => 2019-03-26T06:45:27.941Z, logstash_1 | "tags" => [ logstash_1 | [0] "multiline" logstash_1 | ], logstash_1 | "host" => "751b3a8bf341", logstash_1 | "ChainId" => [], logstash_1 | "message" => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<root>\r\n <ChainId>7290027600007</ChainId>\r\n <SubChainId>001</SubChainId>\r\n <StoreId>001</StoreId>\r\n <BikoretNo>9</BikoretNo>\r\n <DllVerNo>8.0.1.3</DllVerNo>\r\n</root>\r", logstash_1 | "path" => "/usr/share/logstash/logs/example1.xml", logstash_1 | "@version" => "1", logstash_1 | "type" => "xml" logstash_1 | }
XML body under message is showing as a string with escaping and \r\n
. XPathChainId
field returns empty array. I tried with other XML files as well with same results.
Update:
After trying to remove \r\n
still not getting XPath parsed fields. My output is:
logstash_1 | "message" => "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root> <ChainId>7290027600007</ChainId> <SubChainId>001</SubChainId> <StoreId>001</StoreId> <BikoretNo>9</BikoretNo> <DllVerNo>8.0.1.3</DllVerNo>", logstash_1 | "StoreId" => [], logstash_1 | "BikoretNo" => [], logstash_1 | "ChainId" => [], logstash_1 | "type" => "xml", logstash_1 | "tags" => [ logstash_1 | [0] "multiline" logstash_1 | ], logstash_1 | "@timestamp" => 2019-03-27T20:51:09.575Z, logstash_1 | "DllVerNo" => [], logstash_1 | "path" => "/usr/share/logstash/logs/example1.xml", logstash_1 | "host" => "751b3a8bf341", logstash_1 | "SubChainId" => [], logstash_1 | "@version" => "1" logstash_1 | }