# Logstash xml filter with xpath with multiple fields query

**URL:** <https://discuss.elastic.co/t/logstash-xml-filter-with-xpath-with-multiple-fields-query/116185>\
**Category:** Logstash\
**Created:** [January 19, 2018, 8:28am UTC](https://discuss.elastic.co/t/logstash-xml-filter-with-xpath-with-multiple-fields-query/116185 "2018-01-19T08:28:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![moriol](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@moriol](https://discuss.elastic.co/u/moriol)\
**Post date:** [January 19, 2018, 8:28am UTC](https://discuss.elastic.co/t/logstash-xml-filter-with-xpath-with-multiple-fields-query/116185/1 "2018-01-19T08:28:57Z")

</div>

I have an xml file, which contains fields like:

With xpath, within xml filter, I get the fields returned as below, with each element in its array:  
"PhaseName" =\> [  
[0] "CRITICAL",  
[1] "TEST",  
[2] "OTHER",  
[3] "XYZ"  
]  
"PhaseState" =\> [  
[0] "NA",  
[1] "NA",  
[2] "NA",  
[3] "SUCCESSFUL"  
]  
How to format xpath, to return data corresponding to the correct field, in an array together?  
Looking to achieve result such as:  
{GlobalState=OK  
[Phase Name=\>"CRITICAL", State=\>"NA"]  
[Phase Name=\>"TEST", State=\>"NA"]  
}  
I can have multiple phase states, for each given output.

---

<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:** [January 28, 2018, 9:33pm UTC](https://discuss.elastic.co/t/logstash-xml-filter-with-xpath-with-multiple-fields-query/116185/2 "2018-01-28T21:33:20Z")

</div>

You'll have to use a ruby filter. This exact question came up a couple of months ago so you might be able to find a solution in that thread. The zip function of Ruby arrays should be useful to you.

---

<div class="post-metadata">

**Author:** ![moriol](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@moriol](https://discuss.elastic.co/u/moriol)\
**Post date:** [January 30, 2018, 9:55am UTC](https://discuss.elastic.co/t/logstash-xml-filter-with-xpath-with-multiple-fields-query/116185/3 "2018-01-30T09:55:57Z")

</div>

Hi Magnus,

I have found a ruby solution for this, just as you say. I parsed the data and then was able to use the following:  
ruby {  
code =\> '  
event.set("GlobalState", event.get("[parsed][specifc-location][0][GlobalState]"))  
'  
}

Thanks for your suggestion.

---

<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 27, 2018, 9:55am UTC](https://discuss.elastic.co/t/logstash-xml-filter-with-xpath-with-multiple-fields-query/116185/4 "2018-02-27T09:55:59Z")

</div>

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