# Append metadata to every event in XML file being ingested to Elasticsearch

**URL:** <https://discuss.elastic.co/t/append-metadata-to-every-event-in-xml-file-being-ingested-to-elasticsearch/165914>\
**Category:** Logstash\
**Created:** [January 27, 2019, 7:23pm UTC](https://discuss.elastic.co/t/append-metadata-to-every-event-in-xml-file-being-ingested-to-elasticsearch/165914 "2019-01-27T19:23:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhilash\_B](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhilash_b/32/40270_2.png) [@Abhilash\_B](https://discuss.elastic.co/u/Abhilash_B)\
**Post date:** [January 27, 2019, 7:23pm UTC](https://discuss.elastic.co/t/append-metadata-to-every-event-in-xml-file-being-ingested-to-elasticsearch/165914/1 "2019-01-27T19:23:25Z")

</div>

Hey, I have a xml file as follows and I want to append the metadata which are the first few lines of the document to every event in the xml file in subsequent lines.

The xml file is [attached here](https://pastebin.com/mphwNsXr). The expected output for the first event document is [attached here](https://pastebin.com/mSdDA1xV).

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [January 27, 2019, 9:20pm UTC](https://discuss.elastic.co/t/append-metadata-to-every-event-in-xml-file-being-ingested-to-elasticsearch/165914/2 "2019-01-27T21:20:35Z")

</div>

I assume your xml file will have \</events\> and \</eventdata\>. If not it is not valid XML, but that can be fixed with a mutate+ gsub to append text to the message if needed.

Consume the entire XML as a single event using a file input and a multiline codec that never matches. For example

```
codec => multiline { pattern => "^Spalanzani" negate => true what => "previous" auto_flush_interval => 1 } 

```

Then you can parse the XML and split on the event field

```
xml { source => "message" target => "theXML" store_xml => true }
split { field => "[theXML][events][0][event]" }

```

Then you just have [mutate+rename](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-rename) all the fields to get them where you want them.

---

<div class="post-metadata">

**Author:** ![Abhilash\_B](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhilash_b/32/40270_2.png) [@Abhilash\_B](https://discuss.elastic.co/u/Abhilash_B)\
**Post date:** [January 28, 2019, 7:00am UTC](https://discuss.elastic.co/t/append-metadata-to-every-event-in-xml-file-being-ingested-to-elasticsearch/165914/3 "2019-01-28T07:00:23Z")

</div>

@Badger, Thats sounds good, but how do I capture metadata details like "deploymentid" and "siteid" and duplicate it to every event document?

---

<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:** [February 25, 2019, 7:00am UTC](https://discuss.elastic.co/t/append-metadata-to-every-event-in-xml-file-being-ingested-to-elasticsearch/165914/4 "2019-02-25T07:00:34Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
