<?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 pass a parameter from one search query to another as a search argument? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133649#M184657</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have a situation where I want to do the following:&lt;BR /&gt;
search field_1 from (index_1 and sourcetype_1) and then search field_2 from (index_2 and sourcetype_2) using the field_1&lt;/P&gt;

&lt;P&gt;basically I have two different source files which have separate indexes as well as sourcetypes. Only common identifier is field_1. now I want to get the value of field_2.&lt;/P&gt;

&lt;P&gt;Can somebody help me achieving this using a single query?&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 16:24:09 GMT</pubDate>
    <dc:creator>pramit46</dc:creator>
    <dc:date>2020-09-28T16:24:09Z</dc:date>
    <item>
      <title>How to pass a parameter from one search query to another as a search argument?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133649#M184657</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have a situation where I want to do the following:&lt;BR /&gt;
search field_1 from (index_1 and sourcetype_1) and then search field_2 from (index_2 and sourcetype_2) using the field_1&lt;/P&gt;

&lt;P&gt;basically I have two different source files which have separate indexes as well as sourcetypes. Only common identifier is field_1. now I want to get the value of field_2.&lt;/P&gt;

&lt;P&gt;Can somebody help me achieving this using a single query?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:24:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133649#M184657</guid>
      <dc:creator>pramit46</dc:creator>
      <dc:date>2020-09-28T16:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a parameter from one search query to another as a search argument?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133650#M184658</link>
      <description>&lt;P&gt;I think there's some ambiguity in the question but I also think this answer cuts both ways.&lt;/P&gt;

&lt;P&gt;1) If you want the index_2 search to ultimately run a search that looks like &lt;CODE&gt;(field1=field1_value1 OR field1=field1_value2 OR field1=field1_value3 OR...)&lt;/CODE&gt;, then&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=index_2 sourcetype=sourcetype_2 [search index=index_1 sourcetype=sourcetype_1 | fields field_1]&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;2) if you want to use the values of field_1 in the first search,  to search for those values in the field_2 fields....  then: &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=index_2 sourcetype=sourcetype_2 [search index=index_1 sourcetype=sourcetype_1 | fields field_1 | rename field_1 as field_2]&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;In the latter, the outside search is ultimately using a searchterm that looks like &lt;CODE&gt;( field1=field2_value1 OR field1=field2_value2 OR field1=field2_value3 OR ...)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;UPDATE: &lt;BR /&gt;
Hmm... based on this "Only common identifier is field_1. now I want to get the value of field_2.",  I think both the above may be off.  It's amazing how precise you have to be to accurately describe a search language problem. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt; &lt;/P&gt;

&lt;P&gt;If you can update your question with more details to remove ambiguity I'll update my answer. &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:24:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133650#M184658</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2020-09-28T16:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a parameter from one search query to another as a search argument?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133651#M184659</link>
      <description>&lt;P&gt;Indeed, clarification is needed - this may well end in a &lt;CODE&gt;stats by field1&lt;/CODE&gt; or &lt;CODE&gt;join field1&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Apr 2014 16:57:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133651#M184659</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-04-16T16:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a parameter from one search query to another as a search argument?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133652#M184660</link>
      <description>&lt;P&gt;Well, I guess, there is an assumption that field_1 (or field_2) is a multivalued field. If it is, then I apologize, it is not. I should have been more clear.&lt;/P&gt;

&lt;P&gt;Let's assume that both the logs are stored in the form of XML. One stores customer detail (cust_id is the unique value), and other stores his bank information (which also has the same cust_id field). &lt;/P&gt;

&lt;P&gt;Now, I want to retrieve the cust_id from the first log and pass it to the second one to get his bank_account_nbr(I'm assuming that there is only one bank account for each customer). Both the logs have separate indexes and sourcetypes.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:24:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133652#M184660</guid>
      <dc:creator>pramit46</dc:creator>
      <dc:date>2020-09-28T16:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a parameter from one search query to another as a search argument?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133653#M184661</link>
      <description>&lt;P&gt;Give this a shot:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=index_1 sourcetype=sourcetype_1) OR (index=index_2 sourcetype=sourcetype_2) | stats values(bank_account_nbr) by cust_id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That'll create a table of customers with their bank account number.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Apr 2014 07:17:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133653#M184661</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-04-17T07:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a parameter from one search query to another as a search argument?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133654#M184662</link>
      <description>&lt;P&gt;Awesome!!!... that works. I was also curious about clubbing multiple indexes and sourcetypes (I mean, more than just 2), and your suggestions answer that, too.Thanks a lot to both of you.&lt;BR /&gt;
Just one question, what if the fieldname is different in both the logs but the value remains same. eg: if in the first log cust_id:001 whereas in the second log, Customer_ID=001. Can I relate them?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:24:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133654#M184662</guid>
      <dc:creator>pramit46</dc:creator>
      <dc:date>2020-09-28T16:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a parameter from one search query to another as a search argument?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133655#M184663</link>
      <description>&lt;P&gt;You can do a lot of kinds of surgical renames/conversions/normalizations with the &lt;CODE&gt;eval&lt;/CODE&gt; command and it's long list of useful functions. &lt;/P&gt;

&lt;P&gt;Here's a way to rename &lt;CODE&gt;Customer_ID&lt;/CODE&gt; to &lt;CODE&gt;cust_id&lt;/CODE&gt; if &lt;CODE&gt;cust_id&lt;/CODE&gt; is absent but leave it alone if it is already present:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| eval cust_id=if(isnull(cust_id),Customer_ID,cust_id)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;and here's a way to create a third field called &lt;CODE&gt;c_id&lt;/CODE&gt; &lt;BR /&gt;
&lt;CODE&gt;| eval c_id=coalesce(cust_id,Customer_ID)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;(and in that case you would of course do your &lt;CODE&gt;stats values(bank_account_nbr) by c_id&lt;/CODE&gt;)&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Apr 2014 16:23:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133655#M184663</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2014-04-17T16:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a parameter from one search query to another as a search argument?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133656#M184664</link>
      <description>&lt;P&gt;Additionally, you could set up field aliases for the various ways to name a customer ID field to one common name and use that without having a large eval in every query. &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0.3/Knowledge/Addaliasestofields"&gt;http://docs.splunk.com/Documentation/Splunk/6.0.3/Knowledge/Addaliasestofields&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Apr 2014 17:11:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133656#M184664</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-04-17T17:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a parameter from one search query to another as a search argument?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133657#M184665</link>
      <description>&lt;P&gt;martin_mueller, I tried the query you had provided earlier &amp;lt;(index=index_1 sourcetype=sourcetype_1) OR (index=index_2 sourcetype=sourcetype_2) | stats values(bank_account_nbr) by cust_id&amp;gt;; somehow, I feel that it would only consider the latter part (as both cust_id and bank_account_nbr are present in the second part of the query) and ignore the first part since we are using OR. I tried to use AND instead and found no result. Then I removed the first part (which is before 'OR') and got the same result.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:25:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-a-parameter-from-one-search-query-to-another-as-a/m-p/133657#M184665</guid>
      <dc:creator>pramit46</dc:creator>
      <dc:date>2020-09-28T16:25:17Z</dc:date>
    </item>
  </channel>
</rss>

