# Continuosly import XML files from a directory

**URL:** <https://discuss.elastic.co/t/continuosly-import-xml-files-from-a-directory/33401>\
**Category:** Logstash\
**Created:** [October 30, 2015, 4:47pm UTC](https://discuss.elastic.co/t/continuosly-import-xml-files-from-a-directory/33401 "2015-10-30T16:47:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandro1976](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@sandro1976](https://discuss.elastic.co/u/sandro1976)\
**Post date:** [October 30, 2015, 4:47pm UTC](https://discuss.elastic.co/t/continuosly-import-xml-files-from-a-directory/33401/1 "2015-10-30T16:47:04Z")

</div>

Hello everyone,

I am new to elastic, so please forgive me if my questions are not correctly formed.  
I setup a Kibana-\>Elasticsearch-\>Logstash to store and analyze logs of a call server, that are sent to logstash via syslog. This works pretty good and, even if i have to figure out how to build useful queries on Kibana, i am ok for now.  
This call server produces also Call Details Records, that are basically small xml files, each one describing one call, that the call server drops in a directory when at the hangup.  
I would like that logstash contninuosly import this files into ES.  
I tried a input file plugin (with a \*.xml file pattern) and a

xml {  
source =\> "message"  
}

filter... but this seems not working.  
Can anyone point me to the right direction?

Thank you in advance,  
SB

---

<div class="post-metadata">

**Author:** ![RobT](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@RobT](https://discuss.elastic.co/u/RobT)\
**Post date:** [October 30, 2015, 4:55pm UTC](https://discuss.elastic.co/t/continuosly-import-xml-files-from-a-directory/33401/2 "2015-10-30T16:55:21Z")

</div>

begin by setting your target within the xml filter ( i.e. target =\> "my\_xml" )

---

<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 30, 2015, 6:02pm UTC](https://discuss.elastic.co/t/continuosly-import-xml-files-from-a-directory/33401/3 "2015-10-30T18:02:28Z")

</div>

Are the XML documents spread over multiple lines in each file? That's going to make it a bit tricky. Also, Logstash has no support for deleting or moving a file after all of it has been processed, which sounds like something that would be useful for you.

---

<div class="post-metadata">

**Author:** ![sandro1976](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@sandro1976](https://discuss.elastic.co/u/sandro1976)\
**Post date:** [November 2, 2015, 4:26pm UTC](https://discuss.elastic.co/t/continuosly-import-xml-files-from-a-directory/33401/4 "2015-11-02T16:26:06Z")

</div>

Yes, unfortunately each xml files is "human-readably" formatted that, in this case, i understood it is a problem.  
The fact that every XML file has an unique name could be useful to me?

However i understood that logstash is "biased" to work with logfiles, that usually are organized in rows in a single file. I wonder if I am using the right tool for this job, or there is another way to import these files in an elasticsearch db.

Thanks for helping.

---

<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:** [November 2, 2015, 6:27pm UTC](https://discuss.elastic.co/t/continuosly-import-xml-files-from-a-directory/33401/5 "2015-11-02T18:27:36Z")

</div>

I think you can make good use of Logstash, but perhaps not for the initial XML file parsing. I'd write a small script that reads these files and converts their contents to a format that suits Logstash better. To avoid double-processing of the files they would be deleted or renamed after they've been handed off to Logstash (possibly via another file).

---

<div class="post-metadata">

**Author:** ![sandro1976](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@sandro1976](https://discuss.elastic.co/u/sandro1976)\
**Post date:** [November 2, 2015, 11:55pm UTC](https://discuss.elastic.co/t/continuosly-import-xml-files-from-a-directory/33401/6 "2015-11-02T23:55:01Z")

</div>

Maybe a bash cronjob that removes newlines from the xml file, and append the one-line XML output to a log file ... and make logstash work on that?

Convert the XML doc to a CSV is a lot more work...

---

<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:** [November 3, 2015, 7:50am UTC](https://discuss.elastic.co/t/continuosly-import-xml-files-from-a-directory/33401/7 "2015-11-03T07:50:48Z")

</div>

> Maybe a bash cronjob that removes newlines from the xml file, and append the one-line XML output to a log file ... and make logstash work on that?

Yes, something like that should be enough.

---

<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:24am UTC](https://discuss.elastic.co/t/continuosly-import-xml-files-from-a-directory/33401/8 "2017-07-06T05:24:23Z")

</div>


