<?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 How to use a column of field names FROM MVFIELD to dynamically select fields for use in eval expression? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635505#M220788</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Hi,&lt;BR /&gt;I am looking for a solution to a problem that has been addressed here:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A title="Using a column of field names to dynamically select fields for use in eval expression" href="https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365082" target="_blank" rel="noopener"&gt;Using a column of field names to dynamically select fields for use in eval expression&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but with this difference:&lt;/P&gt;
&lt;P&gt;Original solution was:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval raw="x1 y1 z1 field1 x1::x2 y2 z2 field3 z2::x3 y3 z3 field2 y3" 
| makemv delim="::" raw 
| mvexpand raw 
| rex field=raw "(?&amp;lt;field1&amp;gt;\S+)\s+(?&amp;lt;field2&amp;gt;\S+)\s+(?&amp;lt;field3&amp;gt;\S+)\s+(?&amp;lt;lookup&amp;gt;\S+)\s+(?&amp;lt;expected_result&amp;gt;\S+)"
| fields - raw _time
| rename COMMENT AS "Everything above fakes sample data; everything below is your solution."
| eval result="N/A"
| foreach field* [eval result=if(lookup="&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;", $&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;$, result)]&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the&amp;nbsp;&lt;STRONG&gt; | foreach...&lt;/STRONG&gt; command is used &lt;STRONG&gt;field*&lt;/STRONG&gt; as an set of input fields. But in my case the set of input fields cannot be described by wildcard, there is lot of field names in my input "list".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have decided to create multivalue field with all values in lookup column:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| eventstats values(lookup) as mv_lookup&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That created mv field &lt;STRONG&gt;mv_lookup&lt;/STRONG&gt; I want to use as input for &lt;STRONG&gt;| foreach...&lt;/STRONG&gt; command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| foreach mode=multivalue mv_lookup [eval result=if(lookup="&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;", $&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;$, result)]&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess, if foreach command input is MV field, i have to use &amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt; instead of &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; and that is the reason for no match in &lt;STRONG&gt;lookup="&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"&lt;/STRONG&gt;&amp;nbsp;&lt;BR /&gt;Does exist any way how to use MV list of values (names of fields) to perform requested lookup?&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;P&gt;David&lt;/P&gt;</description>
    <pubDate>Wed, 22 Mar 2023 15:41:08 GMT</pubDate>
    <dc:creator>dpuhr</dc:creator>
    <dc:date>2023-03-22T15:41:08Z</dc:date>
    <item>
      <title>How to use a column of field names FROM MVFIELD to dynamically select fields for use in eval expression?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635505#M220788</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi,&lt;BR /&gt;I am looking for a solution to a problem that has been addressed here:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A title="Using a column of field names to dynamically select fields for use in eval expression" href="https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365082" target="_blank" rel="noopener"&gt;Using a column of field names to dynamically select fields for use in eval expression&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but with this difference:&lt;/P&gt;
&lt;P&gt;Original solution was:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval raw="x1 y1 z1 field1 x1::x2 y2 z2 field3 z2::x3 y3 z3 field2 y3" 
| makemv delim="::" raw 
| mvexpand raw 
| rex field=raw "(?&amp;lt;field1&amp;gt;\S+)\s+(?&amp;lt;field2&amp;gt;\S+)\s+(?&amp;lt;field3&amp;gt;\S+)\s+(?&amp;lt;lookup&amp;gt;\S+)\s+(?&amp;lt;expected_result&amp;gt;\S+)"
| fields - raw _time
| rename COMMENT AS "Everything above fakes sample data; everything below is your solution."
| eval result="N/A"
| foreach field* [eval result=if(lookup="&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;", $&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;$, result)]&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the&amp;nbsp;&lt;STRONG&gt; | foreach...&lt;/STRONG&gt; command is used &lt;STRONG&gt;field*&lt;/STRONG&gt; as an set of input fields. But in my case the set of input fields cannot be described by wildcard, there is lot of field names in my input "list".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have decided to create multivalue field with all values in lookup column:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| eventstats values(lookup) as mv_lookup&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That created mv field &lt;STRONG&gt;mv_lookup&lt;/STRONG&gt; I want to use as input for &lt;STRONG&gt;| foreach...&lt;/STRONG&gt; command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| foreach mode=multivalue mv_lookup [eval result=if(lookup="&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;", $&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;$, result)]&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess, if foreach command input is MV field, i have to use &amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt; instead of &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; and that is the reason for no match in &lt;STRONG&gt;lookup="&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"&lt;/STRONG&gt;&amp;nbsp;&lt;BR /&gt;Does exist any way how to use MV list of values (names of fields) to perform requested lookup?&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 15:41:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635505#M220788</guid>
      <dc:creator>dpuhr</dc:creator>
      <dc:date>2023-03-22T15:41:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a column of field names FROM MVFIELD to dynamically select fields for use in eval expression?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635511#M220789</link>
      <description>&lt;P&gt;You seem to have the answer already.&amp;nbsp; Have you tried&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| foreach mode=multivalue mv_lookup [eval result=if(lookup="&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;", $&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;$, result)]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What was the result?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 18:56:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635511#M220789</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-03-22T18:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: Using a column of field names FROM MVFIELD to dynamically select fields for use in eval expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635520#M220794</link>
      <description>&lt;P&gt;I'm sorry, it does not work.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dpuhr_0-1679500695371.png" style="width: 782px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/24437iA45C5A9362C9A0CB/image-dimensions/782x520?v=v2" width="782" height="520" role="button" title="dpuhr_0-1679500695371.png" alt="dpuhr_0-1679500695371.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You can try to run it by yourself:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval raw="x1 y1 z1 field1 x1::x2 y2 z2 field3 z2::x3 y3 z3 field2 y3" 
| makemv delim="::" raw 
| mvexpand raw 
| rex field=raw "(?&amp;lt;field1&amp;gt;\S+)\s+(?&amp;lt;field2&amp;gt;\S+)\s+(?&amp;lt;field3&amp;gt;\S+)\s+(?&amp;lt;lookup&amp;gt;\S+)\s+(?&amp;lt;expected_result&amp;gt;\S+)"
| eventstats values(lookup) as mv_lookup
| fields - raw _time
| eval result="N/A"
| foreach mode=multivalue mv_lookup [eval result=if(lookup="&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;", $&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;$, result)]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am afraid, that &lt;STRONG&gt;$&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;$&lt;/STRONG&gt;&amp;nbsp;cannot be filled with the value from the &lt;STRONG&gt;field&lt;/STRONG&gt;&amp;nbsp;field1, field2 or field3... It works only if &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; keyword is used, I guess &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Does exist any method how get results in this case?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 16:16:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635520#M220794</guid>
      <dc:creator>dpuhr</dc:creator>
      <dc:date>2023-03-22T16:16:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a column of field names FROM MVFIELD to dynamically select fields for use in eval expression?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635620#M220832</link>
      <description>&lt;P&gt;Even if your input fields doesn't fit into a neatly prefixed wildcard expression, wildcard still works. &amp;nbsp;Why no this?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| foreach * [eval result=if(lookup="&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;", $&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;$, result)]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 06:28:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635620#M220832</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-03-23T06:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a column of field names FROM MVFIELD to dynamically select fields for use in eval expression?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635629#M220834</link>
      <description>&lt;P&gt;Not sure how multivalue helps - try something like this (depending on your actual field names and the quality of your actual data, you may need some quotes etc. to deal with non-alphanumerics in field names, and other exception handling)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval raw="w1 x1 y1 z1 field2 x1::w2 x2 y2 z2 field4 z2::w3 x3 y3 z3 field3 y3" 
| makemv delim="::" raw 
| mvexpand raw 
| rex field=raw "(?&amp;lt;field1&amp;gt;\S+)\s+(?&amp;lt;field2&amp;gt;\S+)\s+(?&amp;lt;field3&amp;gt;\S+)\s+(?&amp;lt;field4&amp;gt;\S+)\s+(?&amp;lt;lookup&amp;gt;\S+)\s+(?&amp;lt;expected_result&amp;gt;\S+)"
| fields - raw _time
| eval lookup__{lookup}=lookup
| foreach lookup__*
    [| eval result=if(isnotnull(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;),&amp;lt;&amp;lt;MATCHSEG1&amp;gt;&amp;gt;,result)]
| fields - lookup__*&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 23 Mar 2023 07:27:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635629#M220834</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-03-23T07:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a column of field names FROM MVFIELD to dynamically select fields for use in eval expression?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635657#M220844</link>
      <description>&lt;P&gt;Thaks a lot, it works!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I am just thinking about efficiency in case of 10th "fields" i have to create to perform lookup on them.&lt;BR /&gt;Which solution is more efficient, yours, or&amp;nbsp;&lt;STRONG&gt;yuanliu's &lt;/STRONG&gt;one?&lt;BR /&gt;Thanks&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 09:13:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635657#M220844</guid>
      <dc:creator>dpuhr</dc:creator>
      <dc:date>2023-03-23T09:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a column of field names FROM MVFIELD to dynamically select fields for use in eval expression?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635659#M220845</link>
      <description>&lt;P&gt;You could test it - use job inspector to see how long each takes - you may have to run each version multiple times to get an average.&lt;/P&gt;&lt;P&gt;Having said that, it probably depends on the ratio of the number of unique values in lookup to the total number of fields (found by the wildcard list on the foreach command). For ratios greater than 1, I suspect&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;'s solution might be more efficient. For ratios less than 1, I suspect my solution might be more efficient.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 09:22:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635659#M220845</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-03-23T09:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a column of field names FROM MVFIELD to dynamically select fields for use in eval expression?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635670#M220849</link>
      <description>&lt;P&gt;Thanks a lot, it works!&lt;/P&gt;&lt;P&gt;I am just thinking about efficiency. I guess, that subsearch [eval...] run first, so foreach cycle does not process all (*) fields? Am I right?&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 09:39:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635670#M220849</guid>
      <dc:creator>dpuhr</dc:creator>
      <dc:date>2023-03-23T09:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a column of field names FROM MVFIELD to dynamically select fields for use in eval expression?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635712#M220867</link>
      <description>&lt;P&gt;If your problem is resolved, then please click the "Accept as Solution" button to help future readers.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 13:19:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-column-of-field-names-FROM-MVFIELD-to-dynamically/m-p/635712#M220867</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-03-23T13:19:01Z</dc:date>
    </item>
  </channel>
</rss>

