<?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: How to use rex field as subsearch input value in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-field-as-subsearch-input-value/m-p/350070#M103645</link>
    <description>&lt;P&gt;Try these two ways :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| map  search="search index=uat sourcetype=log_layer_2 source='*$SESSION_ID$*'"

| map  search="search index=uat sourcetype=log_layer_2 source=\"*$SESSION_ID$*\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If those don't work, then back up and get one particular value for SESSION_ID and try these, one by one, until you get a result...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | makeresults | eval SESSION_ID="TheSessionID" | table SESSION_ID
 | map  search="search index=uat sourcetype=log_layer_2 source=TheSessionID"

 | makeresults | eval SESSION_ID="TheSessionID" | table SESSION_ID
 | map  search="search index=uat sourcetype=log_layer_2 source='TheSessionID'"

 | makeresults | eval SESSION_ID="TheSessionID" | table SESSION_ID
 | map  search="search index=uat sourcetype=log_layer_2 source=\"TheSessionID\""

 | makeresults | eval SESSION_ID="TheSessionID" | table SESSION_ID
 | map  search="search index=uat sourcetype=log_layer_2 source=\"$SESSION_ID$\""

 | makeresults | eval SESSION_ID="TheSessionID" | table SESSION_ID
 | map  search="search index=uat sourcetype=log_layer_2 source=\"*$SESSION_ID$*\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I don't believe the asterisks should be needed for this, since you have the actual SESSION_ID value.  We are just seeking the right search to go in the map command, and once it works, you can go back to the full search.  &lt;/P&gt;</description>
    <pubDate>Tue, 02 May 2017 04:24:55 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-05-02T04:24:55Z</dc:date>
    <item>
      <title>How to use rex field as subsearch input value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-field-as-subsearch-input-value/m-p/350067#M103642</link>
      <description>&lt;P&gt;My main search will extract a rex field. I want to use this rex field value as a search input in my subsearch so that I can join 2 results together.&lt;/P&gt;

&lt;P&gt;My search is like below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=uat sourcetype=log_layer_1 "login handle: ABCDEFG" | rex field=source "api\.(?[^\.]+)" | dedup SESSION_ID | table SESSION_ID platform_info| join SESSION_ID [search index=uat soucetype=log_layer_2 **source=*SESSION_ID*** "userID=" | rex field=source "log\.(?[^\.]+)" | rex field=_raw "userID=(?[^ ]+)" |dedup SESSION_ID, USER_ID | table SESSION_ID USER_ID] | table SESSION_ID USER_ID platform_info
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Sourcetype log_layer_1 does not have user ID. Sourcetype log_layer_2 does not have field platform_info.&lt;/P&gt;

&lt;P&gt;My question is how can I use the SESSION_ID from main search, as a condition value input in the subsearch (bold part)&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:50:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-field-as-subsearch-input-value/m-p/350067#M103642</guid>
      <dc:creator>hoyomi</dc:creator>
      <dc:date>2020-09-29T13:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to use rex field as subsearch input value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-field-as-subsearch-input-value/m-p/350068#M103643</link>
      <description>&lt;P&gt;The direct answer to the question is, use &lt;CODE&gt;map&lt;/CODE&gt; instead of &lt;CODE&gt;join&lt;/CODE&gt;, and pass the values you are searching for to the mapped search.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=uat sourcetype=log_layer_1 "login handle: ABCDEFG" 
| rex field=source "api.(?&amp;lt;SESSION_ID&amp;gt;[^\.]+)" 
| rex field=_raw "login handle:\s+(?&amp;lt;handle&amp;gt;[^\s]+)"
| dedup SESSION_ID 
| table SESSION_ID platform_info handle
| map  search="search index=uat sourcetype=log_layer_2 source=*$SESSION_ID$* \"userID=\" 
       | rex field=source \"log.(?&amp;lt;SESSION_ID&amp;gt;[^\.]+)\" 
       | rex field=_raw \"userID=(?&amp;lt;USER_ID&amp;gt;[^\s]+)\" 
       | dedup SESSION_ID, USER_ID 
       | table SESSION_ID USER_ID
       | eval platform_info=\"$platform_info$\"
       | eval login_handle=\"handle\"
       | table SESSION_ID USER_ID platform_info login_handle"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you are doing it for more than one user, other than as a one-shot, it's generally going to be more efficient to do something like this, with no join involved at all...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=uat   (sourcetype=log_layer_2 "userID=" ) OR
    (sourcetype=log_layer_1 AND "login handle: ABCDEFG")
| rex field=source "^(?:api|log).(?&amp;lt;SESSION_ID&amp;gt;[^\.]+)" 
| rex field=_raw "userID=(?&amp;lt;USER_ID&amp;gt;[^\s]+)" 
| rex field=_raw "login handle:\s+(?&amp;lt;handle&amp;gt;[^\s]+)"
| stats values(USER_ID) as USER_ID, values(platform_info) as platform_info, values(handle) as login_handle by SESSION_ID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;My assumptions are as follows.  Given that &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;session = "a1b2c3"  
userid  = "user1" 
platform = "plat1"
handle="ABCDEFG"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Your source records for log_layer_1 look like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=log_layer_1   source=api.a1b2c3.something  platform_info=Plat1 _raw="somewhere in the _raw is login handle: ABCDEFG plus stuff"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Your source records for log_layer_2 look like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=log_layer_2   source=log.a1b2c3.something  _raw="somewhere in the _raw is userID=user1 plus stuff"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:50:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-field-as-subsearch-input-value/m-p/350068#M103643</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2020-09-29T13:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to use rex field as subsearch input value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-field-as-subsearch-input-value/m-p/350069#M103644</link>
      <description>&lt;P&gt;Thank you, DalJeanis. This is very promising.&lt;/P&gt;

&lt;P&gt;You assumption is correct. Unfortunately, I cannot use your "more efficient" search because we format our log in a way that on log_layer_2, log files are separated by each individual user sessions. Thus, it relies on the SESSION_ID from log_layer_1 to narrow down the search. Otherwise, search for data in the past 30 days can be extremely slow.&lt;/P&gt;

&lt;P&gt;Regarding your first search string, somehow, it doesn't work as expected. Even if I trim the search to below, the log entries with "userID=" does not return in the results. In fact, the returned results are way less than what it should be by running the mapped search with a real SESSION_ID plugged in directly.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=uat sourcetype=log_layer_1 "login handle: ABCDEFG" 
 | rex field=source "api.(?[^\.]+)" 
 | rex field=_raw "login handle:\s+(?[^\s]+)"
 | dedup SESSION_ID 
 | map  search="search index=uat sourcetype=log_layer_2 source=*$SESSION_ID$*"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any suggestion on what may be wrong?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:54:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-field-as-subsearch-input-value/m-p/350069#M103644</guid>
      <dc:creator>hoyomi</dc:creator>
      <dc:date>2020-09-29T13:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to use rex field as subsearch input value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-field-as-subsearch-input-value/m-p/350070#M103645</link>
      <description>&lt;P&gt;Try these two ways :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| map  search="search index=uat sourcetype=log_layer_2 source='*$SESSION_ID$*'"

| map  search="search index=uat sourcetype=log_layer_2 source=\"*$SESSION_ID$*\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If those don't work, then back up and get one particular value for SESSION_ID and try these, one by one, until you get a result...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | makeresults | eval SESSION_ID="TheSessionID" | table SESSION_ID
 | map  search="search index=uat sourcetype=log_layer_2 source=TheSessionID"

 | makeresults | eval SESSION_ID="TheSessionID" | table SESSION_ID
 | map  search="search index=uat sourcetype=log_layer_2 source='TheSessionID'"

 | makeresults | eval SESSION_ID="TheSessionID" | table SESSION_ID
 | map  search="search index=uat sourcetype=log_layer_2 source=\"TheSessionID\""

 | makeresults | eval SESSION_ID="TheSessionID" | table SESSION_ID
 | map  search="search index=uat sourcetype=log_layer_2 source=\"$SESSION_ID$\""

 | makeresults | eval SESSION_ID="TheSessionID" | table SESSION_ID
 | map  search="search index=uat sourcetype=log_layer_2 source=\"*$SESSION_ID$*\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I don't believe the asterisks should be needed for this, since you have the actual SESSION_ID value.  We are just seeking the right search to go in the map command, and once it works, you can go back to the full search.  &lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 04:24:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-field-as-subsearch-input-value/m-p/350070#M103645</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-05-02T04:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to use rex field as subsearch input value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-field-as-subsearch-input-value/m-p/350071#M103646</link>
      <description>&lt;P&gt;Double quote with escape is the answer. Btw, I actually need the asterisks because log for one SESSION_ID can be split into multiple files, depending on the size.&lt;/P&gt;

&lt;P&gt;Problem solved. Thank you so much.&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 16:18:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-field-as-subsearch-input-value/m-p/350071#M103646</guid>
      <dc:creator>hoyomi</dc:creator>
      <dc:date>2017-05-02T16:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to use rex field as subsearch input value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-field-as-subsearch-input-value/m-p/350072#M103647</link>
      <description>&lt;P&gt;Heh, so of course, it's the last one I posted...&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 18:26:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-field-as-subsearch-input-value/m-p/350072#M103647</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-05-02T18:26:11Z</dc:date>
    </item>
  </channel>
</rss>

