Hi @magnusbaeck
I am trying to parse the below xml to insert records in Elasticsearch :
<xmldata>
<head1>
<key1>Value1</key1>
<key2>Value2</key2>
<id>0001</id>
<date>01-01-2016 09:00:00</date>
</head1>
<head2>
<key3>Value3</key3>
</head2>
</xmldata>
My Configuration file looks like :
input {
file {
path => ["C:/somepath/text20.xml"]
start_position => beginning
sincedb_path => "/dev/null"
codec => multiline
{
pattern => "<xmldata"
negate => "true"
what => "previous"
auto_flush_interval=>2
}
}
}
filter {
xml {
source => "message"
target => "data"
store_xml => false
xpath => {
"/xmldata/head1/id/text()" => "id"
"/xmldata/head1/key1/text()" => "key1"
"/xmldata/head1/key2/text()" => "key2"
}
}
}
output {
elasticsearch {
codec => json
index => "xtest1"
hosts => ["localhost:9200"]
document_type => "data"
}
stdout { codec => rubydebug }
}
I am able to see the fields mentioned in Xpath on the console with stdout but on elasticsearch those fields are missing. My output on console looks like :
[2018-03-14T13:46:44,391][INFO ][logstash.agent ] Pipelines running {:
count=>1, :pipelines=>["main"]}
{
"message" => "<xmldata>\r\n <head1>\r\n <key1>Value1</key1>\r\n <key2>V
alue2</key2>\r\n <id>0001</id>\r\n <date>01-01-2016 09:00:00</date>\r\n </head
1>\r\n <head2>\r\n <key3>Value3</key3>\r\n </head2>\r\n</xmldata>\r",
"@timestamp" => 2018-03-14T12:46:44.731Z,
"@version" => "1",
"tags" => [
[0] "multiline"
],
"path" => "C:/somepath/text20.
xml",
"host" => "4000511768",
"id" => [
[0] "0001"
],
"key1" => [
[0] "Value1"
],
"key2" => [
[0] "Value2"
]
}
But the id, key1, key2 fields are not present in my elasticsearch Index.
When I modify my config file with :-
mutate {
add_field => { "ID" => "%{id}"
"KEY1" => "%{key1}"
"KEY2" => "%{key2}"
}
remove_field => ["message"]
}
Then I am able to see those fields in my elasticsearch index.
But shouldn't the fields parsed in Xpath be present in elasticsearch as well if I am seeing them on the Stdout ? Can some help me resolve this issue.
The elasticsearch version : 5.6.1 and Logstash version : 6.2.2