<?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 the regex matched variables from the first search into the other search to get all matching results in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707852#M239388</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/275213"&gt;@sarathi125&lt;/a&gt;&amp;nbsp;FYI: Although you have a solution, using &lt;STRONG&gt;join&amp;nbsp;&lt;/STRONG&gt;is not a Splunk way of doing things, joining data sets should really be done using &lt;STRONG&gt;stats&lt;/STRONG&gt;, it's faster, more efficient and does not have the limitations of join, which will silently discard results if the join subsearch exceeds 50,000 results - this may not be an issue in your case, but it's good practice to get your head around using stats to achieve joins.&lt;/P&gt;&lt;P&gt;I also recommend you sort out the automatic field extraction so that you don't have to manually extract jobId - which then means you can use the fields in subsearches and only then have to make a single search.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jan 2025 02:50:32 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2025-01-02T02:50:32Z</dc:date>
    <item>
      <title>How to use the regex matched variables from the first search into the other search to get all matching results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707759#M239367</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I am searching UiPath Orchestrator Logs in Splunk as following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="&amp;lt;indexname&amp;gt;" source = "user1" OR source = "user2" "&amp;lt;ProcessName&amp;gt;" "Exception occurred" | rex field=message "(?&amp;lt;dynamic_text&amp;gt;jobId:\s*\w+)"
| search dynamic_text!=null
| stats values(dynamic_text) AS extracted_texts | map search="index="&amp;lt;indexname&amp;gt;" source = "user1" OR source = "user2" dynamic_text=\"$extracted_texts$\""&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;with my above search, I'll have to reference the jobId matched field from the first search to get other matching records to process transaction details&lt;/P&gt;&lt;P&gt;Thanks a lot in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 31 Dec 2024 02:00:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707759#M239367</guid>
      <dc:creator>sarathi125</dc:creator>
      <dc:date>2024-12-31T02:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the regex matched variables from the first search into the other search to get all matching results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707764#M239369</link>
      <description>&lt;P&gt;Map is generally NOT a solution to searches. This is a potential use of a subsearch, i.e.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="&amp;lt;indexname&amp;gt;" source = "user1" OR source = "user2" [
  search index="&amp;lt;indexname&amp;gt;" source = "user1" OR source = "user2" 
  "&amp;lt;ProcessName&amp;gt;" "Exception occurred" 
  | rex field=message "(?&amp;lt;dynamic_text&amp;gt;jobId:\s*\w+)"
  | search dynamic_text!=null
  | stats values(dynamic_text) AS dynamic_text 
]&lt;/LI-CODE&gt;&lt;P&gt;So here you are using a subsearch to get all the dynamic_text values you want and then that is passed as a constraint to the outer search.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Dec 2024 04:58:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707764#M239369</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2024-12-31T04:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the regex matched variables from the first search into the other search to get all matching results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707808#M239376</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/6367"&gt;@bowesmana&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I have tried with that, but not getting any results. Actually I am trying to match the jobid from the below message. And using this jobId I have get other records which are all matching with this jobid&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sarathi125_0-1735651602840.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/33967i6DF3AAF69101F693/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sarathi125_0-1735651602840.png" alt="sarathi125_0-1735651602840.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Dec 2024 14:11:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707808#M239376</guid>
      <dc:creator>sarathi125</dc:creator>
      <dc:date>2024-12-31T14:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the regex matched variables from the first search into the other search to get all matching results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707809#M239377</link>
      <description>Have you try a spath command as you have json data in use?</description>
      <pubDate>Tue, 31 Dec 2024 14:19:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707809#M239377</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2024-12-31T14:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the regex matched variables from the first search into the other search to get all matching results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707813#M239378</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/214410"&gt;@isoutamo&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;No, I have not tried with spath, Could you please guide me with that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried with the below, its showing events, but not getting the transaction level information&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="&amp;lt;indexname&amp;gt;" source = "user1"  OR source = "user2" "&amp;lt;ProcessName&amp;gt;" "Exception occurred"
| spath
| table _time JobId TransactionId _raw
| search JobId=*
| append [ search index="&amp;lt;indexname&amp;gt;" source = "user1"  OR source = "user2"
           | spath 
           | search JobId=* 
           | table _time JobId TransactionId _raw ]
| stats dc(TransactionId) as UniqueTransactionCount values(TransactionId) as UniqueTransactions by JobId&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 31 Dec 2024 20:02:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707813#M239378</guid>
      <dc:creator>sarathi125</dc:creator>
      <dc:date>2024-12-31T20:02:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the regex matched variables from the first search into the other search to get all matching results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707837#M239382</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/6367"&gt;@bowesmana&lt;/a&gt;&amp;nbsp;says, map is generally not suitable for what you are trying to do. &amp;nbsp;Instead of illustrating an imagined SPL snippet for volunteers to read your mind, it is better to ask yourself, and illustrate:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;What is a meaningful dataset to illustrate my problem? Action: Illustrate said dataset using text. (Screenshot does not apply. &amp;nbsp;Anonymize as needed.)&lt;/LI&gt;&lt;LI&gt;What is the information I am trying to obtain? &amp;nbsp;Action: Illustrate your desired output based on the dataset.&lt;/LI&gt;&lt;LI&gt;What is the logic between my sample dataset and desired output? &amp;nbsp;Use plain language, not SPL. &amp;nbsp;Make your intention clear in logical terms. &amp;nbsp;Use common mathematical/logical symbols if you like, but not SPL if you have any doubt about your code.&lt;/LI&gt;&lt;LI&gt;If you illustrate some SPL that does not give you desired output, also illustrate actual results from the sample dataset. &amp;nbsp;Then, explain why the result differs from desired output unless the reason is &lt;STRONG&gt;painfully&lt;/STRONG&gt; obvious.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Before I try to read your mind, let me point out one critical point you need to clarify - I will use your "first search" to exemplify. &amp;nbsp;Do you try to search for events with terms&amp;nbsp;"&amp;lt;ProcessName&amp;gt;" &lt;U&gt;and&lt;/U&gt; "Exception occurred" only in source=user2, then&amp;nbsp;&lt;EM&gt;all&lt;/EM&gt; events from source=user1? Because that's what your first search does. &amp;nbsp;Your second search has the same logic, therefore IF that map command works, events in source=user1 will always match. &amp;nbsp;Is this really your intention?&lt;/P&gt;&lt;P&gt;I have a high suspicion that you want to search for events with terms "&amp;lt;ProcessName&amp;gt;" &lt;U&gt;and&lt;/U&gt; "Exception occurred" in either source=user1 or source=user2. &amp;nbsp;Is this correct? &amp;nbsp;I will assume so in the following.&lt;/P&gt;&lt;P&gt;This being said, based on the screenshot snippet you shared, you don't need to use regex or even spath to extract jobId because Splunk has clearly done that for you. &amp;nbsp;The field name is Properties.jobId. &amp;nbsp;All you need to do is to match this field.&lt;/P&gt;&lt;P&gt;In other words, given these 8 simplified events:&lt;/P&gt;&lt;TABLE width="781px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="40px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="60.25px"&gt;source&lt;/TD&gt;&lt;TD width="679.75px"&gt;_raw&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="40px"&gt;1&lt;/TD&gt;&lt;TD width="60.25px"&gt;user1&lt;/TD&gt;&lt;TD width="679.75px"&gt;{"Level": "Error", "MessageTemplate": "Exception occurred - something something", "Properties": { "jobId": "8ef3e2f8-35c4-4f0a-8553-cffd718640b", "message": "&amp;lt;ProcessNotName2&amp;gt; Exception occurred - Exception Source: System.Activities stuff, stuff" } }&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="40px"&gt;2&lt;/TD&gt;&lt;TD width="60.25px"&gt;user1&lt;/TD&gt;&lt;TD width="679.75px"&gt;{"Level": "Error", "MessageTemplate": "Exception occurred - something more", "Properties": { "jobId": "8ef3e2f8-2903-4f0a-8553-cffd718640b", "message": "&amp;lt;ProcessName&amp;gt; Exception occurred - Exception Source: System.Activities stuff, stuff" } }&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="40px"&gt;3&lt;/TD&gt;&lt;TD width="60.25px"&gt;user1&lt;/TD&gt;&lt;TD width="679.75px"&gt;{"Level": "Info", "MessageTemplate": "Exception did not occurr - something else", "Properties": { "jobId": "8ef3e2f8-1234-4f0a-8572-cffd718640b", "message": "Exception won't happen - blah" } }&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="40px"&gt;4&lt;/TD&gt;&lt;TD width="60.25px"&gt;user1&lt;/TD&gt;&lt;TD width="679.75px"&gt;{"Level": "Info", "MessageTemplate": "Not exception - something else", "Properties": { "jobId": "8ef3e2f8-5678-4f0a-8553-cffd718640b", "message": "Nothing to see here - don't worry" } }&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="40px"&gt;5&lt;/TD&gt;&lt;TD width="60.25px"&gt;user2&lt;/TD&gt;&lt;TD width="679.75px"&gt;{"Level": "Error", "MessageTemplate": "Exception occurred - something more", "Properties": { "jobId": "8ef3e2f8-35c4-4f0a-8553-cffd718640b", "message": "Exception occurred - Exception Source: System.Activities stuff, stuff" } }&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="40px"&gt;6&lt;/TD&gt;&lt;TD width="60.25px"&gt;user2&lt;/TD&gt;&lt;TD width="679.75px"&gt;{"Level": "Error", "MessageTemplate": "Exception occurred - something something", "Properties": { "jobId": "8ef3e2f8-2903-4f0a-8553-cffd718640b", "message": "Exception occurred - Exception Source: System.Activities stuff, stuff" } }&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="40px"&gt;7&lt;/TD&gt;&lt;TD width="60.25px"&gt;user2&lt;/TD&gt;&lt;TD width="679.75px"&gt;{"Level": "Info", "MessageTemplate": "Exception did not occurr - something else", "Properties": { "jobId": "8ef3e2f8-2903-4f0a-8572-cffd718640b", "message": "Exception won't happen - blah" } }&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="40px"&gt;8&lt;/TD&gt;&lt;TD width="60.25px"&gt;user2&lt;/TD&gt;&lt;TD width="679.75px"&gt;{"Level": "Info", "MessageTemplate": "Not exception - something else", "Properties": { "jobId": "8ef3e2f8-2903-4f0a-8553-cffd718640b", "message": "Nothing to see here - don't worry" } }&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;you want to select 2, 6, and 8.&lt;/P&gt;&lt;P&gt;This is the search to use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="&amp;lt;indexname&amp;gt;" (source = "user1" OR source = "user2") [
  search index="&amp;lt;indexname&amp;gt;" (source = "user1" OR source = "user2" )
  "&amp;lt;ProcessName&amp;gt;" "Exception occurred" 
  | stats values(Properties.jobId) AS Properties.jobId
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the data emulation to generate the mock dataset posted above. &amp;nbsp;Play with it and compare with real data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval data = mvappend(
"{\"Level\": \"Error\",
  \"MessageTemplate\": \"Exception occurred - something something\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-35c4-4f0a-8553-cffd718640b\",
    \"message\": \"&amp;lt;ProcessNotName2&amp;gt; Exception occurred - Exception Source: System.Activities stuff, stuff\"
  }
}",
"{\"Level\": \"Error\",
  \"MessageTemplate\": \"Exception occurred - something more\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-2903-4f0a-8553-cffd718640b\",
    \"message\": \"&amp;lt;ProcessName&amp;gt; Exception occurred - Exception Source: System.Activities stuff, stuff\"
  }
}",
"{\"Level\": \"Info\",
  \"MessageTemplate\": \"Exception did not occurr - something else\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-1234-4f0a-8572-cffd718640b\",
    \"message\": \"Exception won't happen - blah\"
  }
}",
"{\"Level\": \"Info\",
  \"MessageTemplate\": \"Not exception - something else\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-5678-4f0a-8553-cffd718640b\",
    \"message\": \"Nothing to see here - don't worry\"
  }
}"
)
| mvexpand data
| rename data AS _raw
| spath
| eval source = "user1"
| append
    [| makeresults
| eval data = mvappend(
"{\"Level\": \"Error\",
  \"MessageTemplate\": \"Exception occurred - something more\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-35c4-4f0a-8553-cffd718640b\",
    \"message\": \"Exception occurred - Exception Source: System.Activities stuff, stuff\"
  }
}",
"{\"Level\": \"Error\",
  \"MessageTemplate\": \"Exception occurred - something something\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-2903-4f0a-8553-cffd718640b\",
    \"message\": \"Exception occurred - Exception Source: System.Activities stuff, stuff\"
  }
}",
"{\"Level\": \"Info\",
  \"MessageTemplate\": \"Exception did not occurr - something else\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-2903-4f0a-8572-cffd718640b\",
    \"message\": \"Exception won't happen - blah\"
  }
}",
"{\"Level\": \"Info\",
  \"MessageTemplate\": \"Not exception - something else\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-2903-4f0a-8553-cffd718640b\",
    \"message\": \"Nothing to see here - don't worry\"
  }
}"
)
| mvexpand data
| rename data AS _raw
| spath
| eval source = "user2"]
``` the above emulates
index="&amp;lt;indexname&amp;gt;" (source = "user1" OR source = "user2")
```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using this emulation in both main search and subsearch, here is a full emulation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval data = mvappend(
"{\"Level\": \"Error\",
  \"MessageTemplate\": \"Exception occurred - something something\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-35c4-4f0a-8553-cffd718640b\",
    \"message\": \"&amp;lt;ProcessNotName2&amp;gt; Exception occurred - Exception Source: System.Activities stuff, stuff\"
  }
}",
"{\"Level\": \"Error\",
  \"MessageTemplate\": \"Exception occurred - something more\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-2903-4f0a-8553-cffd718640b\",
    \"message\": \"&amp;lt;ProcessName&amp;gt; Exception occurred - Exception Source: System.Activities stuff, stuff\"
  }
}",
"{\"Level\": \"Info\",
  \"MessageTemplate\": \"Exception did not occurr - something else\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-1234-4f0a-8572-cffd718640b\",
    \"message\": \"Exception won't happen - blah\"
  }
}",
"{\"Level\": \"Info\",
  \"MessageTemplate\": \"Not exception - something else\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-5678-4f0a-8553-cffd718640b\",
    \"message\": \"Nothing to see here - don't worry\"
  }
}"
)
| mvexpand data
| rename data AS _raw
| spath
| eval source = "user1"
| append
    [| makeresults
| eval data = mvappend(
"{\"Level\": \"Error\",
  \"MessageTemplate\": \"Exception occurred - something more\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-35c4-4f0a-8553-cffd718640b\",
    \"message\": \"Exception occurred - Exception Source: System.Activities stuff, stuff\"
  }
}",
"{\"Level\": \"Error\",
  \"MessageTemplate\": \"Exception occurred - something something\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-2903-4f0a-8553-cffd718640b\",
    \"message\": \"Exception occurred - Exception Source: System.Activities stuff, stuff\"
  }
}",
"{\"Level\": \"Info\",
  \"MessageTemplate\": \"Exception did not occurr - something else\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-2903-4f0a-8572-cffd718640b\",
    \"message\": \"Exception won't happen - blah\"
  }
}",
"{\"Level\": \"Info\",
  \"MessageTemplate\": \"Not exception - something else\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-2903-4f0a-8553-cffd718640b\",
    \"message\": \"Nothing to see here - don't worry\"
  }
}"
)
| mvexpand data
| rename data AS _raw
| spath
| eval source = "user2"]
``` the above emulates
index="&amp;lt;indexname&amp;gt;" (source = "user1" OR source = "user2")
```
| search 
    [makeresults
| eval data = mvappend(
"{\"Level\": \"Error\",
  \"MessageTemplate\": \"Exception occurred - something something\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-35c4-4f0a-8553-cffd718640b\",
    \"message\": \"&amp;lt;ProcessNotName2&amp;gt; Exception occurred - Exception Source: System.Activities stuff, stuff\"
  }
}",
"{\"Level\": \"Error\",
  \"MessageTemplate\": \"Exception occurred - something more\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-2903-4f0a-8553-cffd718640b\",
    \"message\": \"&amp;lt;ProcessName&amp;gt; Exception occurred - Exception Source: System.Activities stuff, stuff\"
  }
}",
"{\"Level\": \"Info\",
  \"MessageTemplate\": \"Exception did not occurr - something else\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-1234-4f0a-8572-cffd718640b\",
    \"message\": \"Exception won't happen - blah\"
  }
}",
"{\"Level\": \"Info\",
  \"MessageTemplate\": \"Not exception - something else\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-5678-4f0a-8553-cffd718640b\",
    \"message\": \"Nothing to see here - don't worry\"
  }
}"
)
| mvexpand data
| rename data AS _raw
| spath
| eval index = "&amp;lt;indexname&amp;gt;", source = "user1"
| append
    [| makeresults
| eval data = mvappend(
"{\"Level\": \"Error\",
  \"MessageTemplate\": \"Exception occurred - something more\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-35c4-4f0a-8553-cffd718640b\",
    \"message\": \"Exception occurred - Exception Source: System.Activities stuff, stuff\"
  }
}",
"{\"Level\": \"Error\",
  \"MessageTemplate\": \"Exception occurred - something something\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-2903-4f0a-8553-cffd718640b\",
    \"message\": \"Exception occurred - Exception Source: System.Activities stuff, stuff\"
  }
}",
"{\"Level\": \"Info\",
  \"MessageTemplate\": \"Exception did not occurr - something else\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-2903-4f0a-8572-cffd718640b\",
    \"message\": \"Exception won't happen - blah\"
  }
}",
"{\"Level\": \"Info\",
  \"MessageTemplate\": \"Not exception - something else\",
  \"Properties\": {
    \"jobId\": \"8ef3e2f8-2903-4f0a-8553-cffd718640b\",
    \"message\": \"Nothing to see here - don't worry\"
  }
}"
)
| mvexpand data
| rename data AS _raw
| spath
| eval source = "user2"]
    | search "&amp;lt;ProcessName&amp;gt;" "Exception occurred"
``` the above emulates
index="&amp;lt;indexname&amp;gt;" (source = "user1" OR source = "user2")  "ProcessName" "Exception occurred"
```
    | stats values(Properties.jobId) as Properties.jobId
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output is these three events:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;source&lt;/TD&gt;&lt;TD&gt;_raw&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;user1&lt;/TD&gt;&lt;TD&gt;{"Level": "Error", "MessageTemplate": "Exception occurred - something more", "Properties": { "jobId": "8ef3e2f8-2903-4f0a-8553-cffd718640b", "message": "&amp;lt;ProcessName&amp;gt; Exception occurred - Exception Source: System.Activities stuff, stuff" } }&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;user2&lt;/TD&gt;&lt;TD&gt;{"Level": "Error", "MessageTemplate": "Exception occurred - something something", "Properties": { "jobId": "8ef3e2f8-2903-4f0a-8553-cffd718640b", "message": "Exception occurred - Exception Source: System.Activities stuff, stuff" } }&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;user2&lt;/TD&gt;&lt;TD&gt;{"Level": "Info", "MessageTemplate": "Not exception - something else", "Properties": { "jobId": "8ef3e2f8-2903-4f0a-8553-cffd718640b", "message": "Nothing to see here - don't worry" } }&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2025 07:59:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707837#M239382</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2025-01-01T07:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the regex matched variables from the first search into the other search to get all matching results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707846#M239384</link>
      <description>&lt;P class="lia-align-left"&gt;If you run the search that gives you that output in Verbose mode, you will see the fields that are automatically extracted.&lt;/P&gt;&lt;P class="lia-align-left"&gt;If jobId is a field that is automatically extracted, then you should write a basic search that looks for all the jobIds you want - you tried to do that with your rex statement, but you actually included the text "jobId:..." in the dynamic_text, you actually want the jobId data without "jobId:".&lt;/P&gt;&lt;P class="lia-align-left"&gt;As&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/214410"&gt;@isoutamo&lt;/a&gt;&amp;nbsp;says, if jobId is NOT auto-extracted, then use spath to get it and then do the stats on the jobId, e.g. this is the SUBSEARCH - which if you run it on its own will return a single field called jobId with all the jobIds you want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="&amp;lt;indexname&amp;gt;" source = "user1" OR source = "user2" where 
  "&amp;lt;ProcessName&amp;gt;" "Exception occurred" 
  | spath Properties.jobId ``` This uses spath to extract the jobId ```
  | search Properties.jobId!=null
  | stats values(jobId) AS jobId 
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then use this as the subsearch to the outer search and it will then find all records that have a jobId matching the ones you are selecting.&lt;/P&gt;&lt;P&gt;Note that if your jobId is NOT auto extracted, then you cannot make a search for jobId=X, so you will need to either configure Splunk to auto extract the JSON or create a calculated field with this type of expression&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval jobId=spath(_raw, "Properties.jobId")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which will mean jobId will always be a field in your data for search, so you won't have to use the spath expression in your search&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2025 00:50:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707846#M239384</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2025-01-02T00:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the regex matched variables from the first search into the other search to get all matching results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707847#M239385</link>
      <description>&lt;P&gt;In your screenshot, the field jobId had a lower case J, whereas you're using JobId - field names are case sensitive. Also when you use simple spath to extract all fields, they will have the JSON hierarchy in their field names, i.e. the jobId is the field Properties.jobId, not jobId&lt;/P&gt;&lt;P&gt;Also, this is all achievable without using append, so try the subsearch to do the constraints for the outer&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2025 00:51:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707847#M239385</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2025-01-02T00:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the regex matched variables from the first search into the other search to get all matching results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707851#M239387</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/6367"&gt;@bowesmana&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;With the below query able to achieve what I have tried to get,&amp;nbsp; Thank you for your input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="&amp;lt;index&amp;gt;" (source="user1" OR source="user2") "The transaction reference id is" 
| rex field=_raw "\"jobId\":\s?\"(?&amp;lt;jobId&amp;gt;[a-fA-F0-9\-]+)\""                    
| join jobId [
    search index="&amp;lt;index&amp;gt;" (source="user1" OR source="user2") ("&amp;lt;ProcessName&amp;gt;" AND "Exception occurred")
    | rex field=_raw "\"jobId\":\s?\"(?&amp;lt;jobId&amp;gt;[a-fA-F0-9\-]+)\""                        
    | table jobId, _time, _raw
]
| table _time, jobId, _raw&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2025 01:54:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707851#M239387</guid>
      <dc:creator>sarathi125</dc:creator>
      <dc:date>2025-01-02T01:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the regex matched variables from the first search into the other search to get all matching results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707852#M239388</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/275213"&gt;@sarathi125&lt;/a&gt;&amp;nbsp;FYI: Although you have a solution, using &lt;STRONG&gt;join&amp;nbsp;&lt;/STRONG&gt;is not a Splunk way of doing things, joining data sets should really be done using &lt;STRONG&gt;stats&lt;/STRONG&gt;, it's faster, more efficient and does not have the limitations of join, which will silently discard results if the join subsearch exceeds 50,000 results - this may not be an issue in your case, but it's good practice to get your head around using stats to achieve joins.&lt;/P&gt;&lt;P&gt;I also recommend you sort out the automatic field extraction so that you don't have to manually extract jobId - which then means you can use the fields in subsearches and only then have to make a single search.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2025 02:50:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-regex-matched-variables-from-the-first-search/m-p/707852#M239388</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2025-01-02T02:50:32Z</dc:date>
    </item>
  </channel>
</rss>

