<?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 in Multisearch in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Foreach-in-Multisearch/m-p/416870#M119955</link>
    <description>&lt;P&gt;@tiagofbmm Thanks so much! &lt;/P&gt;</description>
    <pubDate>Fri, 01 Mar 2019 22:53:51 GMT</pubDate>
    <dc:creator>mstjohn_splunk</dc:creator>
    <dc:date>2019-03-01T22:53:51Z</dc:date>
    <item>
      <title>Foreach in Multisearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-in-Multisearch/m-p/416865#M119950</link>
      <description>&lt;P&gt;Hi, I wonder whether someone can help me please.&lt;/P&gt;

&lt;P&gt;I've put together the query below using the foreach command, which, although I've read a lot of posts, I've not really used, or if truth be known understood a great deal.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| multisearch
[ search `gateway_wmf(ClientRequest)` path=*vat*]
[ search `wso2_wmf(RequestCompleted)` "request.detail.apiContext"=*test]
| eval RequestID=coalesce('request.tags.X-Request-ID','requestID')
| dedup eventId
| rename request.detail.applicationProductionClientId as ClientID response.detail.statusCode AS statusCode
| foreach clientHeaders.test* [eval header='&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;']
| stats count(header) by RequestID 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The query runs, but there is no new field called "header" created and hence I don't receive my stats count at the end of the query.&lt;/P&gt;

&lt;P&gt;Could someone perhaps have a look a this please and offer some guidance on where I've gone wrong and a brief explanation of the 'foreach' command.&lt;/P&gt;

&lt;P&gt;Many thanks and kind regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 07:14:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-in-Multisearch/m-p/416865#M119950</guid>
      <dc:creator>IRHM73</dc:creator>
      <dc:date>2019-02-28T07:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach in Multisearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-in-Multisearch/m-p/416866#M119951</link>
      <description>&lt;P&gt;If there is no &lt;STRONG&gt;header&lt;/STRONG&gt; field on the search result I guess there is no fields clientHeaders.test with a suffix. &lt;/P&gt;

&lt;P&gt;Check this dummy example, where only one field called header is created, which seems to not have much logic when framing this with the &lt;STRONG&gt;foreach&lt;/STRONG&gt; command&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| makeresults | eval clientHeaders.test1=1, clientHeaders.test2=2&lt;BR /&gt;
 | foreach clientHeaders.test* [eval header='&amp;lt;&amp;gt;']&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;If you want a field header_ for each of the clientHeaders.test, you can use&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| makeresults | eval clientHeaders.test1=1, clientHeaders.test2=2&lt;BR /&gt;
 | foreach clientHeaders.test* [eval header_&amp;lt;&amp;gt;='&amp;lt;&amp;gt;']&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;In my opinion it doesn't seem to be what you want to achieve from what I get from your query. Would you put here an anonymyzed example of  existing fields at this point:&lt;/P&gt;

&lt;P&gt;| multisearch&lt;BR /&gt;
 [ search &lt;CODE&gt;gateway_wmf(ClientRequest)&lt;/CODE&gt; path=&lt;EM&gt;vat&lt;/EM&gt;]&lt;BR /&gt;
 [ search &lt;CODE&gt;wso2_wmf(RequestCompleted)&lt;/CODE&gt; "request.detail.apiContext"=*test]&lt;BR /&gt;
 | eval RequestID=coalesce('request.tags.X-Request-ID','requestID')&lt;BR /&gt;
 | dedup eventId&lt;BR /&gt;
 | rename request.detail.applicationProductionClientId as ClientID response.detail.statusCode AS statusCode&lt;/P&gt;

&lt;P&gt;And get us what you want to get in the end?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 08:18:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-in-Multisearch/m-p/416866#M119951</guid>
      <dc:creator>tiagofbmm</dc:creator>
      <dc:date>2019-02-28T08:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach in Multisearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-in-Multisearch/m-p/416867#M119952</link>
      <description>&lt;P&gt;Hi @tiagofbmm . Thank you for taking the time to come back to me with this.&lt;/P&gt;

&lt;P&gt;The query I posted is correct except for the  .test. It is something mores restricted but the process should be the same and so I have changed this when I use it in my system.&lt;/P&gt;

&lt;P&gt;There are up to 15 'client,header' fields and may be more in the future so I thought, perhaps wrongly that by using 'foreach clientHeaders.test*' would future proof.&lt;/P&gt;

&lt;P&gt;Many thanks and kind regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 09:18:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-in-Multisearch/m-p/416867#M119952</guid>
      <dc:creator>IRHM73</dc:creator>
      <dc:date>2019-02-28T09:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach in Multisearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-in-Multisearch/m-p/416868#M119953</link>
      <description>&lt;P&gt;Hi @tiagofbmm would you mind copying this solution, and posting it in this post: &lt;A href="https://answers.splunk.com/answers/730424/foreach-in-multisearch-1.html"&gt;https://answers.splunk.com/answers/730424/foreach-in-multisearch-1.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Unfortunately, this question is a duplicate of another post, which mean that I have to close it.&lt;/P&gt;

&lt;P&gt;Thanks, and let me know if you have any questions.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 21:01:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-in-Multisearch/m-p/416868#M119953</guid>
      <dc:creator>mstjohn_splunk</dc:creator>
      <dc:date>2019-02-28T21:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach in Multisearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-in-Multisearch/m-p/416869#M119954</link>
      <description>&lt;P&gt;@mstjohn_splunk  no worries, it's done &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2019 11:04:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-in-Multisearch/m-p/416869#M119954</guid>
      <dc:creator>tiagofbmm</dc:creator>
      <dc:date>2019-03-01T11:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach in Multisearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-in-Multisearch/m-p/416870#M119955</link>
      <description>&lt;P&gt;@tiagofbmm Thanks so much! &lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2019 22:53:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-in-Multisearch/m-p/416870#M119955</guid>
      <dc:creator>mstjohn_splunk</dc:creator>
      <dc:date>2019-03-01T22:53:51Z</dc:date>
    </item>
  </channel>
</rss>

