<?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: Join two splunk searches in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Join-two-splunk-searches/m-p/704378#M238686</link>
    <description>&lt;P&gt;Several problems with the illustrated search. &amp;nbsp;Most important one is use of join. &amp;nbsp;This is rarely the solution to any problem in Splunk. &amp;nbsp;Then, there is the problem of bad quotation marks.&lt;/P&gt;&lt;P&gt;Even without this, like&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;says, illustrating useful data input is the best way to enable volunteers to help you. &amp;nbsp;Your illustrated search syntax is so mixed up I cannot even tell whether the two searches are using the same index.&lt;/P&gt;&lt;P&gt;Without any assumption about which data source(s) are used, you can get desired result using append and stats, assuming that my speculation about your syntax reflects the correct filter.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=source "status for : *" "Not available"
| rex field=_raw "status for : (?&amp;lt;ORDERS&amp;gt;.*?)"
| fields ORDERS
| dedup ORDERS
| eval status = "Not available"
| append
    [search Message="Request for : *"
    | rex field=_raw "data=[A-Za-z0-9-]+\|(?P&amp;lt;ORDERS&amp;gt;[\w\.]+)"
    | rex field=_raw "\"unique\"\:\"(?P&amp;lt;UNIQUEID&amp;gt;[A-Z0-9]+)\""
    | fields ORDERS UNIQUEID
    | dedup ORDERS UNIQUEID]
| stats values(*) as * by ORDERS
| where status == "Not available"
| fields - status&lt;/LI-CODE&gt;&lt;P&gt;Note in search command, AND between terms is implied and rarely need to be spelled out.&lt;/P&gt;&lt;P&gt;Now, if the two searches use the same index, it is perhaps more efficient to NOT use append. (Much less join.) &amp;nbsp;Instead, combine the two in one search.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=source (("status for : *" "Not available") OR  Message="Request for : *")
| rex field=_raw "status for : (?&amp;lt;ORDERS&amp;gt;.*?)"
| rex field=_raw "data=[A-Za-z0-9-]+\|(?P&amp;lt;ORDERS&amp;gt;[\w\.]+)"
| rex field=_raw "\"unique\"\:\"(?P&amp;lt;UNIQUEID&amp;gt;[A-Z0-9]+)\""
| fields ORDERS UNIQUEID
| eval not_available = if(searchmatch("Not available"), "yes", null())
| stats values(*) as * by ORDERS
| where isnotnull(not_available)
| fields - not_available&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Nov 2024 06:16:54 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2024-11-14T06:16:54Z</dc:date>
    <item>
      <title>Join two splunk searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-two-splunk-searches/m-p/704240#M238655</link>
      <description>&lt;P&gt;in the outer query i am trying to pull&amp;nbsp; the ORDERS which is&amp;nbsp;&lt;STRONG&gt;Not available&lt;/STRONG&gt;&amp;nbsp;.I need to match the ORDERS&amp;nbsp; which is&amp;nbsp;&lt;STRONG&gt;Not available&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;to with&amp;nbsp;the ORDERS on Sub query.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result to be displayed&amp;nbsp;&amp;nbsp;ORDERS&amp;nbsp; &amp;amp; UNIQUEID .&amp;nbsp;&amp;nbsp;common field in two query is ORDERS&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;my requirement is to use the combine two log statements&amp;nbsp; on "ORDERS"&amp;nbsp; and pull the ORDER and UNIQUEID in table&amp;nbsp; .&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Below is the query i am using , but the result is pulling all ORDERS.&amp;nbsp; i want only the ORDERS and UNIQUEID from subquery to be displayed&amp;nbsp; which matches the ORDERS those&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;Not available &lt;/STRONG&gt;in the first query&amp;nbsp;&amp;nbsp;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=source "status for : *  | "status for : * " AND "Not available"  | rex field=_raw "status for : (?&amp;lt;ORDERS&amp;gt;.*?)" | join ORDERS [search Message=Request for : * | rex field=_raw "data=[A-Za-z0-9-]+\|(?P&amp;lt;ORDERS&amp;gt;[\w\.]+)" | rex field=_raw "\"unique\"\:\"(?P&amp;lt;UNIQUEID&amp;gt;[A-Z0-9]+)\""] | table ORDERS UNIQUEID&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 13 Nov 2024 17:34:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-two-splunk-searches/m-p/704240#M238655</guid>
      <dc:creator>Athira</dc:creator>
      <dc:date>2024-11-13T17:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: Join two splunk searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-two-splunk-searches/m-p/704255#M238657</link>
      <description>&lt;P&gt;Please share some anonymised sample events in code blocks (using the &amp;lt;/&amp;gt; button above) so we can see what you are dealing with.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Nov 2024 08:40:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-two-splunk-searches/m-p/704255#M238657</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-11-13T08:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: Join two splunk searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-two-splunk-searches/m-p/704378#M238686</link>
      <description>&lt;P&gt;Several problems with the illustrated search. &amp;nbsp;Most important one is use of join. &amp;nbsp;This is rarely the solution to any problem in Splunk. &amp;nbsp;Then, there is the problem of bad quotation marks.&lt;/P&gt;&lt;P&gt;Even without this, like&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;says, illustrating useful data input is the best way to enable volunteers to help you. &amp;nbsp;Your illustrated search syntax is so mixed up I cannot even tell whether the two searches are using the same index.&lt;/P&gt;&lt;P&gt;Without any assumption about which data source(s) are used, you can get desired result using append and stats, assuming that my speculation about your syntax reflects the correct filter.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=source "status for : *" "Not available"
| rex field=_raw "status for : (?&amp;lt;ORDERS&amp;gt;.*?)"
| fields ORDERS
| dedup ORDERS
| eval status = "Not available"
| append
    [search Message="Request for : *"
    | rex field=_raw "data=[A-Za-z0-9-]+\|(?P&amp;lt;ORDERS&amp;gt;[\w\.]+)"
    | rex field=_raw "\"unique\"\:\"(?P&amp;lt;UNIQUEID&amp;gt;[A-Z0-9]+)\""
    | fields ORDERS UNIQUEID
    | dedup ORDERS UNIQUEID]
| stats values(*) as * by ORDERS
| where status == "Not available"
| fields - status&lt;/LI-CODE&gt;&lt;P&gt;Note in search command, AND between terms is implied and rarely need to be spelled out.&lt;/P&gt;&lt;P&gt;Now, if the two searches use the same index, it is perhaps more efficient to NOT use append. (Much less join.) &amp;nbsp;Instead, combine the two in one search.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=source (("status for : *" "Not available") OR  Message="Request for : *")
| rex field=_raw "status for : (?&amp;lt;ORDERS&amp;gt;.*?)"
| rex field=_raw "data=[A-Za-z0-9-]+\|(?P&amp;lt;ORDERS&amp;gt;[\w\.]+)"
| rex field=_raw "\"unique\"\:\"(?P&amp;lt;UNIQUEID&amp;gt;[A-Z0-9]+)\""
| fields ORDERS UNIQUEID
| eval not_available = if(searchmatch("Not available"), "yes", null())
| stats values(*) as * by ORDERS
| where isnotnull(not_available)
| fields - not_available&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 06:16:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-two-splunk-searches/m-p/704378#M238686</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-11-14T06:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Join two splunk searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-two-splunk-searches/m-p/704411#M238697</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;thanks for tips, i tried running with the modified query. i got the results for ORDERS which are NOT AVAILABLE (which is the resultant of First search) . my requirement is to match&amp;nbsp;ORDERS which are&amp;nbsp;NOT AVAILABLE with ORDERS in second log . and display&amp;nbsp;ORDERS&amp;nbsp; and UNIQUEID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sharing the data here&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;INFO  [pool-9-thread-3]  CLASS_NAME=Q, METHOD=, MESSAGE=response status for TransNum: 629f2ad - 400 | Response - {"code":0001,"message":"Not available","messages":[],"additionalTxnFields":[]}

INFO  [pool-9-thread-7]  CLASS_NAME=Q, METHOD=, MESSAGE=Request for TransNum: 629f2ad - {"address":{"billToThis":true,"country":"","email":"******************","firstname":"FN","lastname":"LN","postcode":"0","salutation":null,"telephone":"+999999999999"},"deliveryMode":"","payments":[{"amount":10,"code":"BFD"}],"products":[{"currency":356,"price":600,"qty":2,"uniqueid":"QSTRUJIK"}],"refno":"629f2ad","syncOnly":true}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 13:14:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-two-splunk-searches/m-p/704411#M238697</guid>
      <dc:creator>Athira</dc:creator>
      <dc:date>2024-11-14T13:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: Join two splunk searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-two-splunk-searches/m-p/704415#M238698</link>
      <description>&lt;P&gt;Assuming there is only one event per TransNum which has a message field and that TransNum is the correlating field, try something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex "TransNum:\s(?&amp;lt;TransNum&amp;gt;\S+)"
| rex "\"message\":\"(?&amp;lt;message&amp;gt;[^\"]+)"
| eventstats values(message) as message by TransNum
| where message="Not available"&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 14 Nov 2024 13:27:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-two-splunk-searches/m-p/704415#M238698</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-11-14T13:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Join two splunk searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-two-splunk-searches/m-p/704432#M238702</link>
      <description>&lt;P&gt;Thank you for sharing sample data. &amp;nbsp;This reveals additional weaknesses in the pursuit.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;ORDERS seems to be the ID that comes after TransNum, not extracted by the original regex at all. &amp;nbsp;Sample data also show contradiction with your original index search. &amp;nbsp;But that is more for you to fine tune.&lt;/LI&gt;&lt;LI&gt;Part of the event is structured in JSON. &amp;nbsp;This should be treated as a structure not literal strings. &amp;nbsp;Extraction using regex is instable.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Based on your sample events (which suggest that the source is exactly the same, therefore subsearch is really a bad approach), this would be a much better strategy&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=source (("status for" "Not available") OR  "Request for")
| rex "TransNum: (?&amp;lt;ORDERS&amp;gt;\S+) .*?(?&amp;lt;JSON&amp;gt;{.+})"
| spath input=JSON path=products{}
| mvexpand products{}
| spath input=products{}
| stats values(uniqueid) as uniqueid by ORDERS&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Note the index search is purely based on sample data. &amp;nbsp;You may need to tune it to actually include the correct events.) &amp;nbsp;Your sample data will give you&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ORDERS&lt;/TD&gt;&lt;TD&gt;uniqueid&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;629f2ad&lt;/TD&gt;&lt;TD&gt;QSTRUJIK&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Here is an emulation of your data. Play with it and compare with real data and refine your search strategy&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| fields - _*
| eval data = mvappend("INFO  [pool-9-thread-3]  CLASS_NAME=Q, METHOD=, MESSAGE=response status for TransNum: 629f2ad - 400 | Response - {\"code\":0001,\"message\":\"Not available\",\"messages\":[],\"additionalTxnFields\":[]}",
"INFO  [pool-9-thread-7]  CLASS_NAME=Q, METHOD=, MESSAGE=Request for TransNum: 629f2ad - {\"address\":{\"billToThis\":true,\"country\":\"\",\"email\":\"******************\",\"firstname\":\"FN\",\"lastname\":\"LN\",\"postcode\":\"0\",\"salutation\":null,\"telephone\":\"+999999999999\"},\"deliveryMode\":\"\",\"payments\":[{\"amount\":10,\"code\":\"BFD\"}],\"products\":[{\"currency\":356,\"price\":600,\"qty\":2,\"uniqueid\":\"QSTRUJIK\"}],\"refno\":\"629f2ad\",\"syncOnly\":true}")
| mvexpand data
| rename data as _raw
| extract
``` the above emulates
index=source (("status for" "Not available") OR  "Request for")
```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 17:06:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-two-splunk-searches/m-p/704432#M238702</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-11-14T17:06:45Z</dc:date>
    </item>
  </channel>
</rss>

