<?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: subsearch in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-the-result-of-query1-to-as-a-input-string-for-the/m-p/602564#M209748</link>
    <description>&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt; should you add " | format" to then end of subquery?</description>
    <pubDate>Tue, 21 Jun 2022 08:23:09 GMT</pubDate>
    <dc:creator>isoutamo</dc:creator>
    <dc:date>2022-06-21T08:23:09Z</dc:date>
    <item>
      <title>How to pass the result of query1 to as a input string for the second query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-the-result-of-query1-to-as-a-input-string-for-the/m-p/602421#M209687</link>
      <description>&lt;P&gt;Need to pass the result of query1 to as a input string for the second query.&lt;/P&gt;
&lt;P&gt;For the First query i'm getting output(x-corelation id) as a filed, that output field(x-corelation id) as a input for the second query to get errors.&lt;/P&gt;
&lt;P&gt;Attached both queries below, Please find the attachments and help me out with the requirement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;query 1:-&amp;nbsp;&lt;/P&gt;
&lt;P&gt;index=cloud_ecp sourcetype="prod-ecp-aks-cluster-logs" "bookAppointmentRequest" | fields data.req.headers.xcorrelationid&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;query 2 :-&amp;nbsp;&lt;/P&gt;
&lt;P&gt;index=cloud_ecp sourcetype="prod-ecp-aks-cluster-logs" &amp;lt;co-relationid of query1&amp;gt; "Error"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note :- the co-relationid's are more than one, need to loop all those id's if any.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2022 18:04:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-the-result-of-query1-to-as-a-input-string-for-the/m-p/602421#M209687</guid>
      <dc:creator>kiran007</dc:creator>
      <dc:date>2022-06-21T18:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-the-result-of-query1-to-as-a-input-string-for-the/m-p/602422#M209688</link>
      <description />
      <pubDate>Mon, 20 Jun 2022 14:40:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-the-result-of-query1-to-as-a-input-string-for-the/m-p/602422#M209688</guid>
      <dc:creator>kiran007</dc:creator>
      <dc:date>2022-06-20T14:40:14Z</dc:date>
    </item>
    <item>
      <title>Re: subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-the-result-of-query1-to-as-a-input-string-for-the/m-p/602426#M209691</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/234229"&gt;@kiran007&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;let me understand, you want to filter search2, using the ids from search 1, is it correct?&lt;/P&gt;&lt;P&gt;I suppose that the field "data.req.headers.xcorrelationid" is present in both the searches and that search2 hasn't more than 50,000 results.&lt;/P&gt;&lt;P&gt;In this case you could try something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=cloud_ecp sourcetype="prod-ecp-aks-cluster-logs" "Error" [ search index=cloud_ecp sourcetype="prod-ecp-aks-cluster-logs" "bookAppointmentRequest" | fields data.req.headers.xcorrelationid ]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;if&amp;nbsp;"data.req.headers.xcorrelationid" is named in a different way in the main search, you have to rename in the subsearch to be sure that the field name is the same in both searches.&lt;/P&gt;&lt;P&gt;If you could have more than 50,000 results from the subsearch, tell me because the solution is completely different.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 15:01:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-the-result-of-query1-to-as-a-input-string-for-the/m-p/602426#M209691</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-06-20T15:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-the-result-of-query1-to-as-a-input-string-for-the/m-p/602427#M209692</link>
      <description>&lt;P&gt;SPL is _not_ a procedural language. While sometimes you can "loop", you shouldn't do that unless you can't avoid it.&lt;/P&gt;&lt;P&gt;And in this case you probably can.&lt;/P&gt;&lt;P&gt;If I understand your searches correctly, you have many events containing the common field data.req.headers.xcorrelationid. Some of them might contain the string "bookAppointmentRequest" , some (possibly other ones) might contain "Error". And you only want those errors, for which other events with the same data.req.headers.xcorrelationid contain "bookAppointmentRequest".&lt;/P&gt;&lt;P&gt;There are several ways to do it.&lt;/P&gt;&lt;P&gt;First, most obvious but often not the best due to how Splunk works and subsearch limitations is to indeed use subsearch to generate a list of the ID's and only search for those ID's. However, with a relatively small subset of the events with "bookAppointmentRequest" string, it might be the most efficient solution. Be aware however, that subsearches can fail silently if you exceed execution time limit or number of returned results&lt;/P&gt;&lt;PRE&gt;index=cloud_ecp sourcetype="prod-ecp-aks-cluster-logs" "Error" [ index=cloud_ecp sourcetype="prod-ecp-aks-cluster-logs" "bookAppointmentRequest" | table data.req.headers.xcorrelationid ]&lt;/PRE&gt;&lt;P&gt;Second one would be to use a &lt;EM&gt;transaction&lt;/EM&gt; command to group all events with the same ID and only search for those with Errors. Should work but &lt;EM&gt;transaction&lt;/EM&gt; has its limitations as well and is a relatively "heavy" comand.&lt;/P&gt;&lt;PRE&gt;index=cloud_ecp sourcetype="prod-ecp-aks-cluster-logs"&lt;BR /&gt;| transaction data.req.headers.xcorrelationid&lt;BR /&gt;| search "bookAppointmentRequest" "Error"&lt;/PRE&gt;&lt;P&gt;Unfortunately, since you have to scan all events to find the correlation over the xcorrelationid, the search will not be very efficient either way but the preferable approaches usually involve stats or eventstats.&lt;/P&gt;&lt;PRE&gt;index=cloud_ecp sourcetype="prod-ecp-aks-cluster-logs"&lt;BR /&gt;| stats list(_raw) by data.req.headers.xcorrelationid&lt;BR /&gt;| search "bookAppointmentRequest" "Error&lt;/PRE&gt;&lt;P&gt;It's a similar approach to the transaction command but it works slightly differently internally.&lt;/P&gt;&lt;P&gt;Which approach is best here depends on the actual data.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 15:07:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-the-result-of-query1-to-as-a-input-string-for-the/m-p/602427#M209692</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-06-20T15:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-the-result-of-query1-to-as-a-input-string-for-the/m-p/602564#M209748</link>
      <description>&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt; should you add " | format" to then end of subquery?</description>
      <pubDate>Tue, 21 Jun 2022 08:23:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-the-result-of-query1-to-as-a-input-string-for-the/m-p/602564#M209748</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2022-06-21T08:23:09Z</dc:date>
    </item>
  </channel>
</rss>

