# XML + Mutate plugins not working as espected

**URL:** <https://discuss.elastic.co/t/xml-mutate-plugins-not-working-as-espected/162271>\
**Category:** Logstash\
**Created:** [December 27, 2018, 5:28pm UTC](https://discuss.elastic.co/t/xml-mutate-plugins-not-working-as-espected/162271 "2018-12-27T17:28:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alfonso\_Diez](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@Alfonso\_Diez](https://discuss.elastic.co/u/Alfonso_Diez)\
**Post date:** [December 27, 2018, 5:28pm UTC](https://discuss.elastic.co/t/xml-mutate-plugins-not-working-as-espected/162271/1 "2018-12-27T17:28:04Z")

</div>

Hello.  
I've implement a filter where I read from a JMS queue a message that is an XML file.

Then, I use the XML plugin to map some fields with the paths of the XML as following:

> xpath =\> [  
> "//Framework\_Event/EventCode/text()", "EventCode",  
> "//Framework\_Event/E2ERequestId/text()", "E2EId",  
> "//Framework\_Event/ParentInstanceId/text()", "ParentAdapterInstanceId",  
> "//Framework\_Event/InstanceId/text()", "AdapterInstanceId",  
> "//Framework\_Event/CustomId/text()", "AdapterCustomId",  
> "//Framework\_Event/Deepness/text()", "StageLevel",  
> "//Framework\_Event/RequestTimeStamp/text()", "E2EStartTimeStamp",  
> ]

As far as I know, this plugin always extracts an array from the indicated paths.

Then I extract the first element from the array:

> mutate {  
> remove\_field =\> ["message"]  
> replace =\> {  
> "EventCode" =\> "%{[EventCode][0]}"  
> "E2EId" =\> "%{[E2EId][0]}"  
> "ParentAdapterInstanceId" =\> "%{[ParentAdapterInstanceId][0]}"  
> "AdapterInstanceId" =\> "%{[AdapterInstanceId][0]}"  
> "AdapterCustomId" =\> "%{[AdapterCustomId][0]}"  
> "StageLevel" =\> "%{[StageLevel][0]}"  
> "E2EStartTimeStamp" =\> "%{[E2EStartTimeStamp][0]}"  
> }

the problem is that for those elements of the XML that are empty, the replace function is writing something like that in elastic:

> "ParentAdapterInstanceId": "%{[ParentAdapterInstanceId][0]}",

How could I get a blank there instead of this?

many thanks in advance

---

<div class="post-metadata">

**Author:** ![balumurari1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/balumurari1/32/39203_2.png) [@balumurari1](https://discuss.elastic.co/u/balumurari1)\
**Post date:** [December 28, 2018, 12:29pm UTC](https://discuss.elastic.co/t/xml-mutate-plugins-not-working-as-espected/162271/2 "2018-12-28T12:29:31Z")

</div>

try these,

> if ![ParentAdapterInstanceId]{  
> mutate{  
> add\_field =\> {"ParentAdapterInstanceId" =\> "null"}  
> }  
> }

or

> if ![ParentAdapterInstanceId] {  
> mutate {  
> replace =\> {  
> "[ParentAdapterInstanceId]" =\> ""  
> }  
> }  
> }

---

<div class="post-metadata">

**Author:** ![Alfonso\_Diez](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@Alfonso\_Diez](https://discuss.elastic.co/u/Alfonso_Diez)\
**Post date:** [December 28, 2018, 12:56pm UTC](https://discuss.elastic.co/t/xml-mutate-plugins-not-working-as-espected/162271/3 "2018-12-28T12:56:28Z")

</div>

Thank you very much, this solution works for me, but to make the code short what I have done is the following:

> ```
> xpath => [
> "concat(//Framework_Event/EventCode/text(), '')", "EventCode",
> "concat(//Framework_Event/E2ERequestId/text(), '')", "E2EId",
> "concat(//Framework_Event/ParentInstanceId/text(), '')", "ParentAdapterInstanceId",
> "concat(//Framework_Event/InstanceId/text(), '')", "AdapterInstanceId",
> "concat(//Framework_Event/CustomId/text(), '')", "AdapterCustomId",
> "concat(//Framework_Event/Deepness/text(), '')", "StageLevel",
> "concat(//Framework_Event/RequestTimeStamp/text(), '')", "E2EStartTimeStamp",
> ]
> 
> ```

That avoid the content of the field to be null being always blank.

---

<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:** [January 25, 2019, 12:56pm UTC](https://discuss.elastic.co/t/xml-mutate-plugins-not-working-as-espected/162271/4 "2019-01-25T12:56:36Z")

</div>

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