# How to load xml file using logstash in es?

**URL:** <https://discuss.elastic.co/t/how-to-load-xml-file-using-logstash-in-es/40839>\
**Category:** Logstash\
**Created:** [February 3, 2016, 8:48am UTC](https://discuss.elastic.co/t/how-to-load-xml-file-using-logstash-in-es/40839 "2016-02-03T08:48:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![shankarananth.th](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@shankarananth.th](https://discuss.elastic.co/u/shankarananth.th)\
**Post date:** [February 3, 2016, 8:48am UTC](https://discuss.elastic.co/t/how-to-load-xml-file-using-logstash-in-es/40839/1 "2016-02-03T08:48:36Z")

</div>

Hi ,

I'm very new to elk.  
Kindly find my data sample in attachment.  
How can i load that xml data using logstash.  
I used the below mentioned code to load it.

input {  
stdin {  
type =\> "stdin-type"  
}

file {  
type =\> "file"  
path =\> "D:\splunk\_shankar\02-02-2016\data2"  
}  
}  
output {  
elasticsearch {  
action =\> "index"  
protocol =\> "http"  
host =\> "localhost"  
index =\> "dataloadxmltest"

```
}
stdout {}

```

}

 ![](https://us1.discourse-cdn.com/elastic/original/2X/3/3dbb25ea3908c1c498612d7dde2be6b118085150.JPG)

---

<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:** [February 3, 2016, 9:36am UTC](https://discuss.elastic.co/t/how-to-load-xml-file-using-logstash-in-es/40839/2 "2016-02-03T09:36:16Z")

</div>

Is the XML snippet on a line of its own? And all other lines should be ignored?

---

<div class="post-metadata">

**Author:** ![shankarananth.th](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@shankarananth.th](https://discuss.elastic.co/u/shankarananth.th)\
**Post date:** [February 3, 2016, 10:02am UTC](https://discuss.elastic.co/t/how-to-load-xml-file-using-logstash-in-es/40839/3 "2016-02-03T10:02:35Z")

</div>

Hi magnusbaeck,

Can you make it somewhat clear.  
I'm not getting your point.  
what i need to add in filter path, to extract data from the above image.

I need data as mentioned below:

MessageId | date\_month | date\_second | date\_wday | timestartpos  
H2H\_SEND\_MONEY\_STORE\_WGHHTWI800T\_NNCI6UACJ01961\_2016-02-02-053758628319 | february | 0 | tuesday | 123  
Regards,  
Shankar

---

<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:** [February 3, 2016, 10:11am UTC](https://discuss.elastic.co/t/how-to-load-xml-file-using-logstash-in-es/40839/4 "2016-02-03T10:11:07Z")

</div>

Oh, you've edited the question.

The difficulty here isn't parsing the XML itself, that's very easily done with an xml filter. The hard part is getting the whole XML file into a single event. You need to set `start_position => beginning` for the file input and you need a multiline codec for joining the lines of the file.

This has been brought up here several times in the past so please search the archives.

---

<div class="post-metadata">

**Author:** ![shankarananth.th](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@shankarananth.th](https://discuss.elastic.co/u/shankarananth.th)\
**Post date:** [February 3, 2016, 10:14am UTC](https://discuss.elastic.co/t/how-to-load-xml-file-using-logstash-in-es/40839/5 "2016-02-03T10:14:52Z")

</div>

Hi magnusbaeck,

Thank you very much.  
I will go through the archives.

Thanks,  
Shankar

---

<div class="post-metadata">

**Author:** ![shankarananth.th](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@shankarananth.th](https://discuss.elastic.co/u/shankarananth.th)\
**Post date:** [February 3, 2016, 12:01pm UTC](https://discuss.elastic.co/t/how-to-load-xml-file-using-logstash-in-es/40839/6 "2016-02-03T12:01:40Z")

</div>

Hi Magnusbaeck,

Going through the archive.  
I have framed the below mentioned query, but some time its running in logstash and sometime its not running .  
Can u kindly check and point out me what is the Error in the code.

input{  
file {  
path =\> "D:\splunk\_shankar\02-02-2016\data22.xml"  
start\_position =\> beginning  
}  
}

```
filter {
          multiline {
                    pattern => "^\s|</result>|^[A-Za-z0-1].*"
                    what => "previous"
            }
            xml {
                    store_xml => "false"
                    source => "message"
                    target => "doc"
                    xpath => [
                            "/result/@field/@value/@text", "result_text",
                            "/result/@field/@value/@text", "result_text",
                            "/result/@field/@value/@text", "result_text",
                            "/result/@field/@value/@text", "result_text",
                            "/result/@field/@value/@text", "result_text",
                            "/result/@field/@value/@text", "result_text"
                    ]
            }

```

}

output {  
elasticsearch {  
action =\> "index"  
protocol =\> "http"  
host =\> "localhost"  
index =\> "showme"

```
}
stdout {}

```

}

---

<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:** [February 3, 2016, 12:36pm UTC](https://discuss.elastic.co/t/how-to-load-xml-file-using-logstash-in-es/40839/7 "2016-02-03T12:36:20Z")

</div>

That's most likely related to Logstash's tracking of the current position in a file via the sincedb file. `start_position => beginning` only matters the first time a particular file is seen. You can set `sincedb_path => "/dev/null"` to disable this feature.

---

<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:13am UTC](https://discuss.elastic.co/t/how-to-load-xml-file-using-logstash-in-es/40839/8 "2017-07-06T05:13:13Z")

</div>


