<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: foreach with mvexpand to iterate over server fields and perform an expansion in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353008#M104485</link>
    <description>&lt;P&gt;I just added the working query to main answer. &lt;/P&gt;</description>
    <pubDate>Tue, 19 Dec 2017 20:54:10 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2017-12-19T20:54:10Z</dc:date>
    <item>
      <title>foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352989#M104466</link>
      <description>&lt;P&gt;I have various fields like "Server 1" "Server 2" ... And I want to perform an expansion of those fields like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;                       Server 1 | Server 2

                         false  | true
  Property               false  | false
                         true   | true
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example: So the field &lt;STRONG&gt;Property&lt;/STRONG&gt; for the &lt;STRONG&gt;Server1&lt;/STRONG&gt; has multiple values ( false, false, true )&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;foreach Server* [ mvexpand &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; ] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But this don't work. But single expansion works &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;mvexpand Server1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is my idea for iterating every Server field and performing an expansion but I am open to other resolutions aswell! Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 14:47:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352989#M104466</guid>
      <dc:creator>greggz</dc:creator>
      <dc:date>2017-12-19T14:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352990#M104467</link>
      <description>&lt;P&gt;What should be the final output after expansion? (based on  your sample data in question)&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 15:13:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352990#M104467</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-12-19T15:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352991#M104468</link>
      <description>&lt;P&gt;Hello! Something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;              Server1    Server2 

Property      false        true
Property      false       false
Property      true        true
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Dec 2017 15:15:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352991#M104468</guid>
      <dc:creator>greggz</dc:creator>
      <dc:date>2017-12-19T15:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352992#M104469</link>
      <description>&lt;P&gt;And the field names are dynamic or static?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 15:24:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352992#M104469</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-12-19T15:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352993#M104470</link>
      <description>&lt;P&gt;They migth change yes. Hence the "Server*". The Property field name is the same always &lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 15:29:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352993#M104470</guid>
      <dc:creator>greggz</dc:creator>
      <dc:date>2017-12-19T15:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352994#M104471</link>
      <description>&lt;P&gt;Give this workaround a try (runanywhere sample, replace everything before &lt;CODE&gt;| eval temp=""&lt;/CODE&gt; with your  search)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval Property="Test" | table Property | eval Server1=split("true false true"," ") | eval Server2=split("false false true"," ") 
| eval temp="" | foreach Server* [eval temp=if(temp="", '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;',mvzip(temp,'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'))] | mvexpand temp | foreach Server* [eval "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"=mvindex(split(temp,","),&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;-1)] | fields - temp
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Updated - on that worked&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval Property="Test" | table Property | eval UF1=split("true false true"," ") | eval UF2=split("false false true"," ") 
  | eval temp="" | foreach UF* [eval temp=if(temp="", '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;',mvzip(temp,'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'))] | mvexpand temp | eval sno=0| foreach UF* [eval "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"=mvindex(split(temp,","),sno) | eval sno=sno+1] | fields - temp
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Explanation:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval temp="" | foreach UF* [eval temp=if(temp="", '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;',mvzip(temp,'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'))] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Creating a new field temp, which will be combined multivalued field for each of UF field values. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval sno=0| foreach UF* [eval "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"=mvindex(split(temp,","),sno) | eval sno=sno+1] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For each UF* field, I'm overwriting the current value (which can be a multivalued field, to single value from expanded temp values. The field sno is used to find specific values within temp field (temp field is comma separate combined values of &lt;CODE&gt;UF*&lt;/CODE&gt; fields).&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 15:32:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352994#M104471</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-12-19T15:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352995#M104472</link>
      <description>&lt;P&gt;Not working for me. It just sets my fields all blank.. &lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 15:55:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352995#M104472</guid>
      <dc:creator>greggz</dc:creator>
      <dc:date>2017-12-19T15:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352996#M104473</link>
      <description>&lt;P&gt;Does "Split" make the value be an array ? Cause in my sample I think they're represented as an array&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 15:58:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352996#M104473</guid>
      <dc:creator>greggz</dc:creator>
      <dc:date>2017-12-19T15:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352997#M104474</link>
      <description>&lt;P&gt;Just run this and see if the format matches your data. Yes, it's assuming that both Server1 and Server2 (or any other servers) are multivalued field (kind of arrays in Splunk).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval Property="Test" | table Property | eval Server1=split("true false true"," ") | eval Server2=split("false false true"," ") 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Dec 2017 16:21:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352997#M104474</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-12-19T16:21:38Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352998#M104475</link>
      <description>&lt;P&gt;Yes they seem similar. The only difference is that my server names come like "Server-1" "Server-2"&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 16:32:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352998#M104475</guid>
      <dc:creator>greggz</dc:creator>
      <dc:date>2017-12-19T16:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352999#M104476</link>
      <description>&lt;P&gt;Oh and another difference is that my values also come as a single value sometimes. So it's a mix of arrays or a single value ( which I don't need to expand anymore ofc )&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 16:36:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/352999#M104476</guid>
      <dc:creator>greggz</dc:creator>
      <dc:date>2017-12-19T16:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353000#M104477</link>
      <description>&lt;P&gt;Does my full query works for you ? &lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 16:49:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353000#M104477</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-12-19T16:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353001#M104478</link>
      <description>&lt;P&gt;Yep your sample works fine.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 16:56:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353001#M104478</guid>
      <dc:creator>greggz</dc:creator>
      <dc:date>2017-12-19T16:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353002#M104479</link>
      <description>&lt;P&gt;Well, without seeing your current data, it'd be difficult to troubleshoot what causing it not to work. Can you provide some screenshot of your sample data (showing field Property and Servers). Mask/Blackout any sensitive data/actual server names.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 17:04:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353002#M104479</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-12-19T17:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353003#M104480</link>
      <description>&lt;P&gt;Something along these lines:  &lt;A href="https://ibb.co/hxfiLR"&gt;https://ibb.co/hxfiLR&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;And if I try to &lt;CODE&gt;foreach UF* [mvexpand &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; ]&lt;/CODE&gt; this is the result:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://ibb.co/cmiES6"&gt;https://ibb.co/cmiES6&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;My multi value fields are have tripled..  why ?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 17:20:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353003#M104480</guid>
      <dc:creator>greggz</dc:creator>
      <dc:date>2017-12-19T17:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353004#M104481</link>
      <description>&lt;P&gt;Since you're expanding one field at a time, the total number of rows will become N*N (say you've 3 items, first field will yield 3 rows after mvexpand, with second field still multivalued field in all. Second mvexpand will again yield 3 rows for each row). &lt;/P&gt;

&lt;P&gt;What do you get when you just add following to your search??Specially in field temp&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search with field Property UF_* fields 
| eval temp="" | foreach Server* [eval temp=if(temp="", '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;',mvzip(temp,'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'))] | mvexpand temp
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Dec 2017 17:37:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353004#M104481</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-12-19T17:37:53Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353005#M104482</link>
      <description>&lt;P&gt;Oh jeez. So that's what's happening...&lt;/P&gt;

&lt;P&gt;This is what happens in temp. The other UF* remain "Un-Expanded"&lt;/P&gt;

&lt;P&gt;&lt;A href="https://ibb.co/kgBXfR"&gt;https://ibb.co/kgBXfR&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 17:44:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353005#M104482</guid>
      <dc:creator>greggz</dc:creator>
      <dc:date>2017-12-19T17:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353006#M104483</link>
      <description>&lt;P&gt;Got the issue. I kinda assumed that all servernames are integer numbers. Try this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval Property="Test" | table Property | eval UF1=split("true false true"," ") | eval UF2=split("false false true"," ") 
 | eval temp="" | foreach UF* [eval temp=if(temp="", '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;',mvzip(temp,'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'))] | mvexpand temp | eval sno=0| foreach UF* [eval "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"=mvindex(split(temp,","),sno) | eval sno=sno+1] | fields - temp
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Dec 2017 18:47:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353006#M104483</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-12-19T18:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353007#M104484</link>
      <description>&lt;P&gt;Yep it really works, but I've got no clue what's happening in there haha. Better go read the docs! Do you wish to post this as your answer or should I just accept the other one ? Thanks for your time man! Really apreciated it&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 19:33:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353007#M104484</guid>
      <dc:creator>greggz</dc:creator>
      <dc:date>2017-12-19T19:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with mvexpand to iterate over server fields and perform an expansion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353008#M104485</link>
      <description>&lt;P&gt;I just added the working query to main answer. &lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 20:54:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-mvexpand-to-iterate-over-server-fields-and-perform/m-p/353008#M104485</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-12-19T20:54:10Z</dc:date>
    </item>
  </channel>
</rss>

