# Please give me easy sample to use xml filter

**URL:** <https://discuss.elastic.co/t/please-give-me-easy-sample-to-use-xml-filter/31616>\
**Category:** Logstash\
**Created:** [October 5, 2015, 7:57am UTC](https://discuss.elastic.co/t/please-give-me-easy-sample-to-use-xml-filter/31616 "2015-10-05T07:57:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![kikuchan](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@kikuchan](https://discuss.elastic.co/u/kikuchan)\
**Post date:** [October 5, 2015, 7:57am UTC](https://discuss.elastic.co/t/please-give-me-easy-sample-to-use-xml-filter/31616/1 "2015-10-05T07:57:02Z")

</div>

Hello.  
I'd like to use XML filter,but I didn't use it very well.

please give me easy sample to use xml filter.

sincerely.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [October 5, 2015, 8:01am UTC](https://discuss.elastic.co/t/please-give-me-easy-sample-to-use-xml-filter/31616/2 "2015-10-05T08:01:34Z")

</div>

Please give us an example of the XML you want to parse and what result you want to get from it.

---

<div class="post-metadata">

**Author:** ![kikuchan](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@kikuchan](https://discuss.elastic.co/u/kikuchan)\
**Post date:** [October 5, 2015, 8:26am UTC](https://discuss.elastic.co/t/please-give-me-easy-sample-to-use-xml-filter/31616/3 "2015-10-05T08:26:17Z")

</div>

Hello, thanks for following.

please read following contents.

## 1)contents of xml file

## \<?xml version="1.0" encoding="UTF-8"\> \< ROOT number="34"\> \< EVENTLIST\> \< EVENT name="hey"/\> \< EVENT name="you"/\> \< /EVENTLIST\> \< /ROOT\>

2)contents of conf file

* * *

input{  
file {  
path =\> "C:\test.xml"  
type =\> "building"  
start\_position =\> "beginning"  
}  
}

filter {  
xml {  
store\_xml =\> "false"  
source =\> "message"  
target =\> "EVENT"  
xpath =\> ["/ROOT/@number ","number","/ROOT/EVENTLIST/EVENT/@name","name"]  
}  
}

output  
{  
elasticsearch{  
actin =\> "index"  
host =\> "localhost"  
index =\> "XMLTest"  
protocol =\> "transport"  
cluster =\> "cluster\_name"  
manage\_template =\> false  
}  
stdout { codec =\> rubydebug}  
}  
}

* * *

I'm tried to use this conf file and xml file.  
The xml date didn't add Elasticsearch.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [October 5, 2015, 8:28am UTC](https://discuss.elastic.co/t/please-give-me-easy-sample-to-use-xml-filter/31616/4 "2015-10-05T08:28:17Z")

</div>

Please edit your post and format your XML as code so it won't get stripped away.

---

<div class="post-metadata">

**Author:** ![kikuchan](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@kikuchan](https://discuss.elastic.co/u/kikuchan)\
**Post date:** [October 5, 2015, 8:31am UTC](https://discuss.elastic.co/t/please-give-me-easy-sample-to-use-xml-filter/31616/5 "2015-10-05T08:31:23Z")

</div>

sorry, i posted it again.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [October 5, 2015, 8:35am UTC](https://discuss.elastic.co/t/please-give-me-easy-sample-to-use-xml-filter/31616/6 "2015-10-05T08:35:23Z")

</div>

> The xml date didn't add Elasticsearch.

What XML date? The modification time of the input file?

---

<div class="post-metadata">

**Author:** ![kikuchan](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@kikuchan](https://discuss.elastic.co/u/kikuchan)\
**Post date:** [October 5, 2015, 8:40am UTC](https://discuss.elastic.co/t/please-give-me-easy-sample-to-use-xml-filter/31616/7 "2015-10-05T08:40:12Z")

</div>

I found this xml date on the following Web site.

> <https://stackoverflow.com/questions/26362303/logstash-split-event-from-an-xml-file-in-multiples-documents-keeping-informatio>

The modification time of the input file?  
yes, I did.  
Just in case I created a new input file when I start logstash with the conf file.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [October 5, 2015, 8:50am UTC](https://discuss.elastic.co/t/please-give-me-easy-sample-to-use-xml-filter/31616/8 "2015-10-05T08:50:08Z")

</div>

Logstash has nothing built in for picking up the input file's modification time. You could write a small Ruby snippet in a ruby filter though; see [http://stackoverflow.com/a/29970500/414355](http://stackoverflow.com/a/29970500/414355).

---

<div class="post-metadata">

**Author:** ![kikuchan](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@kikuchan](https://discuss.elastic.co/u/kikuchan)\
**Post date:** [October 5, 2015, 8:59am UTC](https://discuss.elastic.co/t/please-give-me-easy-sample-to-use-xml-filter/31616/9 "2015-10-05T08:59:10Z")

</div>

I added this code

filter {  
xml{  
...  
}  
ruby {  
code =\> 'event["mtime"] = File.mtime(event["path"])'  
}  
}

but I can not add xml date.

this is error maybe.  
[error]  
failed action with response of 400, dropping action

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [October 5, 2015, 11:07am UTC](https://discuss.elastic.co/t/please-give-me-easy-sample-to-use-xml-filter/31616/10 "2015-10-05T11:07:13Z")

</div>

> ruby {  
> code =\> 'event["mtime"] = File.mtime(event["path"])'  
> }

You did replace `path` in the Ruby snippet with the actual path to the file, right?

> failed action with response of 400, dropping action

Leave ES out of this until your messages look as you expect. Solve one problem at a time.

That said, I'd look in the Elasticsearch logs for clues. Cranking up the Logstash log level with `--verbose` or even `--debug` could also be useful.

---

<div class="post-metadata">

**Author:** ![kikuchan](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@kikuchan](https://discuss.elastic.co/u/kikuchan)\
**Post date:** [October 13, 2015, 12:50am UTC](https://discuss.elastic.co/t/please-give-me-easy-sample-to-use-xml-filter/31616/11 "2015-10-13T00:50:15Z")

</div>

thanks for your comment!  
I am poised to fail this issue.  
I don't understand this problem.  
so, I gave up to use this xml filter.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 5:26am UTC](https://discuss.elastic.co/t/please-give-me-easy-sample-to-use-xml-filter/31616/12 "2017-07-06T05:26:46Z")

</div>


