<?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 and subsearch in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/foreach-and-subsearch/m-p/540789#M153051</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/227524"&gt;@splunk_new1&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;You can try using map command. Since it is not clear, your final desired output I cannot give you a sample. Please check the documentation below;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/8.1.2/SearchReference/Map" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/8.1.2/SearchReference/Map&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Feb 2021 08:52:48 GMT</pubDate>
    <dc:creator>scelikok</dc:creator>
    <dc:date>2021-02-22T08:52:48Z</dc:date>
    <item>
      <title>foreach and subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-and-subsearch/m-p/540752#M153034</link>
      <description>&lt;P&gt;I am using a table of results&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; a |   b |  c |   search           | d |    e  
===============================================
xx    yy   zzz   index=firstindex    bb    ppp 
yyy  qqq  eeee   index=secondindex   rr    sss
ttt  zxc  asd    index=thirdindex    uy    mmm&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;based on each result,&amp;nbsp; I would like to perform a&amp;nbsp; foreach command to loop through each row of results based on the "search" field and perform a subsearch based on the VALUES in the "search" field,&amp;nbsp; from a coding's perspective it would be something like&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;for each row: 

if field= search: 
      #use value in search
      [search value | return index to main search]

it should evaluate to something like this for each row 

if field=search:
      [search index=index1 | return index]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My desired output is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index  
==============  
firstindex
secondindex
thirdindex&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Is this possible? I have tried using&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;foreach * [eval if &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=="search"[search &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;] ","[search &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;]]&lt;BR /&gt;&lt;BR /&gt;but this does not seem to work.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Tried looking around in splunk community forums but the queries do not seem to be the same as what I am intending to do&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 02:31:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-and-subsearch/m-p/540752#M153034</guid>
      <dc:creator>splunk_new1</dc:creator>
      <dc:date>2021-02-23T02:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: foreach and subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-and-subsearch/m-p/540789#M153051</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/227524"&gt;@splunk_new1&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;You can try using map command. Since it is not clear, your final desired output I cannot give you a sample. Please check the documentation below;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/8.1.2/SearchReference/Map" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/8.1.2/SearchReference/Map&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2021 08:52:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-and-subsearch/m-p/540789#M153051</guid>
      <dc:creator>scelikok</dc:creator>
      <dc:date>2021-02-22T08:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: foreach and subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-and-subsearch/m-p/540812#M153062</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply. I have posted an update to my question with my desired output.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am aware of the map command, however as my field results have the word index= before the actual index name, I am unable to do a&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;search
========================
index=firstindex   
index=secondindex
index=thirdindex&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;|map search="search index=$search$"&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;as I believe ^ would&amp;nbsp; resolve to map search="search index=index=firstindex&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;This would be an error. Is there anyway I can do something like&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|map search="search $search$| stats values(index)"

and have it return something like 

index
==========
firstindex
secondindex
thirdindex&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 22 Feb 2021 10:54:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-and-subsearch/m-p/540812#M153062</guid>
      <dc:creator>splunk_new1</dc:creator>
      <dc:date>2021-02-22T10:54:45Z</dc:date>
    </item>
  </channel>
</rss>

