<?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 Why is multi-value foreach command not returning expected values from template &amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-is-multi-value-foreach-command-not-returning-expected-values/m-p/607276#M211132</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a multi-value field &lt;STRONG&gt;numbers&lt;/STRONG&gt; with each of its values in the format of two numbers separated by a comma (for example 52,29).&amp;nbsp; For all of these values, I want to have an if statement that does a comparison on both the first number and second number and then return either "true" or "false".&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Currently I have been using the foreach loop with the multi-value mode. However, when debugging why I am receiving the error below, I found that the default template value &amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;&amp;nbsp; appears to always return null instead of the values of&amp;nbsp;&lt;STRONG&gt;numbers &lt;/STRONG&gt;(isnotnull('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;') returns False).&lt;BR /&gt;&lt;BR /&gt;Shown below is how I am trying to extract the leftmost number using regex with replace and then check if it is greater than 5.&amp;nbsp;Is there something wrong with this search?&lt;/P&gt;
&lt;P&gt;| foreach mode=multivalue numbers&lt;BR /&gt;&amp;nbsp; &amp;nbsp; [| eval results=if(tonumber(replace('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;'),&amp;nbsp; ",\d+",&amp;nbsp; "")) &amp;gt; 5, "true", "false")]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the error I get for the search above:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Splunk_Hatched_0-1658966271956.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/20720i399A9AAF8C81668E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Splunk_Hatched_0-1658966271956.png" alt="Splunk_Hatched_0-1658966271956.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Jul 2022 14:55:13 GMT</pubDate>
    <dc:creator>Splunk_Hatched</dc:creator>
    <dc:date>2022-07-28T14:55:13Z</dc:date>
    <item>
      <title>Why is multi-value foreach command not returning expected values from template &lt;&lt;ITEM&gt;&gt;?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-multi-value-foreach-command-not-returning-expected-values/m-p/607276#M211132</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a multi-value field &lt;STRONG&gt;numbers&lt;/STRONG&gt; with each of its values in the format of two numbers separated by a comma (for example 52,29).&amp;nbsp; For all of these values, I want to have an if statement that does a comparison on both the first number and second number and then return either "true" or "false".&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Currently I have been using the foreach loop with the multi-value mode. However, when debugging why I am receiving the error below, I found that the default template value &amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;&amp;nbsp; appears to always return null instead of the values of&amp;nbsp;&lt;STRONG&gt;numbers &lt;/STRONG&gt;(isnotnull('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;') returns False).&lt;BR /&gt;&lt;BR /&gt;Shown below is how I am trying to extract the leftmost number using regex with replace and then check if it is greater than 5.&amp;nbsp;Is there something wrong with this search?&lt;/P&gt;
&lt;P&gt;| foreach mode=multivalue numbers&lt;BR /&gt;&amp;nbsp; &amp;nbsp; [| eval results=if(tonumber(replace('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;'),&amp;nbsp; ",\d+",&amp;nbsp; "")) &amp;gt; 5, "true", "false")]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the error I get for the search above:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Splunk_Hatched_0-1658966271956.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/20720i399A9AAF8C81668E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Splunk_Hatched_0-1658966271956.png" alt="Splunk_Hatched_0-1658966271956.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 14:55:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-multi-value-foreach-command-not-returning-expected-values/m-p/607276#M211132</guid>
      <dc:creator>Splunk_Hatched</dc:creator>
      <dc:date>2022-07-28T14:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: Multi-value foreach command not returning expected values from template &lt;&lt;ITEM&gt;&gt;</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-multi-value-foreach-command-not-returning-expected-values/m-p/607280#M211133</link>
      <description>&lt;P&gt;You have too many closing brackets - remove the one after ITEM&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;'&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 03:03:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-multi-value-foreach-command-not-returning-expected-values/m-p/607280#M211133</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-07-28T03:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Multi-value foreach command not returning expected values from template &lt;&lt;ITEM&gt;&gt;</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-multi-value-foreach-command-not-returning-expected-values/m-p/607282#M211134</link>
      <description>&lt;P&gt;First, there's a syntax error: you closed &lt;EM&gt;replace()&lt;/EM&gt; function at &lt;FONT face="andale mono,times"&gt;'&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;'&lt;/FONT&gt;, instead of after &lt;FONT face="andale mono,times"&gt;""&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;But a bigger problem is the unclear requirement. &amp;nbsp; For example, if given two values in &lt;FONT face="andale mono,times"&gt;numbers&lt;/FONT&gt;, if one of them is greater than 5 but another is less than 5, what should &lt;FONT face="andale mono,times"&gt;result&lt;/FONT&gt; be? &amp;nbsp;The solution will depend on such details.&lt;/P&gt;&lt;P&gt;The following will give you a multivalued results, which may not be what you wanted.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| foreach mode=multivalue numbers
    [eval results=mvappend(results, if(tonumber(replace('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;',  ",\d+",  "")) &amp;gt; 5, "true", "false"))]&lt;/LI-CODE&gt;&lt;P&gt;Suppose &lt;FONT face="andale mono,times"&gt;numbers&lt;/FONT&gt; is (8, 2), &lt;FONT face="andale mono,times"&gt;results&lt;/FONT&gt; will be ('&lt;EM&gt;true&lt;/EM&gt;', '&lt;EM&gt;false&lt;/EM&gt;'); if &lt;FONT face="andale mono,times"&gt;numbers&lt;/FONT&gt; is (2, 8), results is ('&lt;EM&gt;false&lt;/EM&gt;', '&lt;EM&gt;true&lt;/EM&gt;')&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 03:17:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-multi-value-foreach-command-not-returning-expected-values/m-p/607282#M211134</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-07-28T03:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: Multi-value foreach command not returning expected values from template &lt;&lt;ITEM&gt;&gt;</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-multi-value-foreach-command-not-returning-expected-values/m-p/607407#M211170</link>
      <description>&lt;P&gt;Hello yuanliu,&lt;/P&gt;&lt;P&gt;Thank you for pointing out the extra parentheses and lack of clarity in my search. Perhaps this adjusted search would help clarify further what I originally intended:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| foreach mode=multivalue numbers
    [eval results=mvappend(results, if(tonumber(replace('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;', ",\d+", "")) &amp;gt; 5 AND tonumber(replace('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;', "^\d+,", "")) &amp;gt; 5, "true", "false"))]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;While this adjusted search is now closer to what I intended, the&amp;nbsp;&lt;STRONG&gt;results&lt;/STRONG&gt; field only creates two outputs when I wanted to create three (one for each of the three values in the&amp;nbsp;&lt;STRONG&gt;numbers&amp;nbsp;&lt;/STRONG&gt;field). The foreach command appears not to have reached the third value.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Splunk_Hatched_0-1659028972380.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/20735i9A21F342C15CF72B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Splunk_Hatched_0-1659028972380.png" alt="Splunk_Hatched_0-1659028972380.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Splunk_Hatched_1-1659029019175.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/20736i33E459F0FF55800D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Splunk_Hatched_1-1659029019175.png" alt="Splunk_Hatched_1-1659029019175.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Further testing to check what '&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;' actually returns appears to give a Null value (see the screenshot of testParseNumbers shown below).&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval testParseNumbers=""
| foreach mode=multivalue numbers
    [eval results=mvappend(results, if(tonumber(replace('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;', ",\d+", "")) &amp;gt; 5 AND tonumber(replace('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;', "^\d+,", "")) &amp;gt; 5, "true", "false")), testParseNumbers=testParseNumbers.tostring('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;')]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Splunk_Hatched_2-1659030125605.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/20737i6A3833D2EB9075B0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Splunk_Hatched_2-1659030125605.png" alt="Splunk_Hatched_2-1659030125605.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I would appreciate suggestions on how to fix this. Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 17:42:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-multi-value-foreach-command-not-returning-expected-values/m-p/607407#M211170</guid>
      <dc:creator>Splunk_Hatched</dc:creator>
      <dc:date>2022-07-28T17:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Multi-value foreach command not returning expected values from template &lt;&lt;ITEM&gt;&gt;</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-multi-value-foreach-command-not-returning-expected-values/m-p/607409#M211172</link>
      <description>&lt;P&gt;Thank you for clearly pointing that out. I would appreciate further feedback about my query in my reply to yuanliu&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 17:46:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-multi-value-foreach-command-not-returning-expected-values/m-p/607409#M211172</guid>
      <dc:creator>Splunk_Hatched</dc:creator>
      <dc:date>2022-07-28T17:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: Multi-value foreach command not returning expected values from template &lt;&lt;ITEM&gt;&gt;</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-multi-value-foreach-command-not-returning-expected-values/m-p/607443#M211184</link>
      <description>&lt;P&gt;The screenshot of &lt;FONT face="andale mono,times"&gt;numbers&lt;/FONT&gt;&amp;nbsp;shows that your values can be negative, which is represented by "-", not matching "\d+". (It really helps to illustrate data in text, especially as yours are already anonymized.) &amp;nbsp;The following should work on that data set&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| foreach mode=multivalue numbers
    [eval results=mvappend(results, if(tonumber(replace('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;', ",[-\d]+", "")) &amp;gt; 5 AND tonumber(replace('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;', "^[-\d]+,", "")) &amp;gt; 5, "true", "false"))]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Using &amp;nbsp;the &amp;nbsp;sample data shown in that screenshot, the output is&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;numbers&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;results&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;-1,-1&lt;/DIV&gt;&lt;DIV class=""&gt;0,25535&lt;/DIV&gt;&lt;DIV class=""&gt;22,3389&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;false&lt;/DIV&gt;&lt;DIV class=""&gt;false&lt;/DIV&gt;&lt;DIV class=""&gt;true&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Is this what you expect? &amp;nbsp;Again, it is perhaps easier to verbalize your criteria, assisted by code or pseudo-code. I interpret &amp;nbsp;your intention as follows: given multivalue pairs of comma-delimited integers, calculate multivalue results; corresponding to each pair, return true if both numbers are greater than 5, false otherwise. (I kind of made this wordier than necessary, but that's the idea.)&lt;/P&gt;&lt;P&gt;I have some suspicion, though, that a multivalue field of &lt;FONT face="andale mono,times"&gt;results&lt;/FONT&gt;&amp;nbsp;may not be what you wanted, as it may complicate subsequent processing.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2022 02:54:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-multi-value-foreach-command-not-returning-expected-values/m-p/607443#M211184</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-07-29T02:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: Multi-value foreach command not returning expected values from template &lt;&lt;ITEM&gt;&gt;</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-multi-value-foreach-command-not-returning-expected-values/m-p/607585#M211254</link>
      <description>&lt;P&gt;Hi yuanliu,&lt;/P&gt;&lt;P&gt;Thank you for pointing out my mistakes in the regex and lack of clarity in my desired criteria. Your description of my intended output for &lt;STRONG&gt;results&lt;/STRONG&gt; are correct.&lt;BR /&gt;You are also correct that a multi-value field is not optimal for my desired &lt;STRONG&gt;results&lt;/STRONG&gt; field. Thinking this over, I resolved the issue by using mvexpand on &lt;STRONG&gt;numbers&lt;/STRONG&gt; before applying the Boolean logic (i.e. expression&amp;gt;5).&lt;/P&gt;&lt;P&gt;I greatly appreciate your help to troubleshoot through both my SPL expressions and the implementation of the search.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2022 20:49:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-multi-value-foreach-command-not-returning-expected-values/m-p/607585#M211254</guid>
      <dc:creator>Splunk_Hatched</dc:creator>
      <dc:date>2022-07-29T20:49:33Z</dc:date>
    </item>
  </channel>
</rss>

