<?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: Combine two record sets where a distinct value matches (without using join) in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320327#M95735</link>
    <description>&lt;P&gt;Thanks @somesoni2! This worked (after noticing timestamp was mispelled on line 7. :-))  &lt;/P&gt;

&lt;P&gt;The only issue I saw is that for records in the final display that didn't have a username (not all records do), there was not a timestamp shown even though one exists. I changed isnotnull to isnull and it seemed to work. I then added a &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| table _time eventid username cardnum
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to the end to get the order presented in the question. &lt;/P&gt;

&lt;P&gt;So, while it all works now, I don't know that I could explain &lt;EM&gt;how&lt;/EM&gt;. I'd love to be able to use your method again in the future but don't know I can follow the logic. Can you help me understand it?&lt;/P&gt;</description>
    <pubDate>Mon, 29 May 2017 03:17:33 GMT</pubDate>
    <dc:creator>chinchin96</dc:creator>
    <dc:date>2017-05-29T03:17:33Z</dc:date>
    <item>
      <title>Combine two record sets where a distinct value matches (without using join)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320322#M95730</link>
      <description>&lt;P&gt;I have a search that generates two distinct types of record entries (searching for "for event"):&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;2015-05-05  for event &lt;STRONG&gt;201216053940303kljdwlj&lt;/STRONG&gt; for recipient &lt;STRONG&gt;Geogm&lt;/STRONG&gt; &lt;/LI&gt;
&lt;LI&gt;2015-05-05  card &lt;STRONG&gt;12345678910&lt;/STRONG&gt; for event &lt;STRONG&gt;201216053940303kljdwlj&lt;/STRONG&gt; &lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Fields I created:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;&lt;P&gt;201216053940303kljdwlj = eventid&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Geogm = username (it's always 6&lt;BR /&gt;
characters long and at the end of the&lt;BR /&gt;
line) &lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;12345678910 = cardnum&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;I want a table that shows the username and eventid of the first type of record and combines it with the card number where the eventid is a match, showing something like the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Time       , username , eventid               , cardnum
2015-05-05 , Geogm    , 201216053940303kljdwlj , 12345678910
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I think I got this working using join, but would like a different way to achieve it due to performance issues of using join.&lt;/P&gt;

&lt;P&gt;My current query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myindex source="source1" OR source="source2"  "for recipient" 
| extract pairdelim="|;,", kvdelim="=:", auto=f  
| rex field=_raw "(?&amp;lt;username&amp;gt;\s......$)" 
| search username!=""  
| rex field=_raw "event (?&amp;lt;eventid&amp;gt;.(\w+))" 
| search eventid !="" 
| table _time username eventid 
| join eventid [search index=myindex source="source1" OR source="source2"  "for event" 
| extract pairdelim="|;,", kvdelim="=:", auto=f  
| rex field=_raw "card (?&amp;lt;cardnum&amp;gt;.(\w+))"  
| search cardnum !=""  
| rex field=_raw "event (?&amp;lt;eventid&amp;gt;.(\w+))"  
| search eventid !="" 
| table  eventid cardnum]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is simlar to the question shown here: answers.splunk.com/answers/443909/how-do-i-joincombine-my-two-search-searches-to-get.html?utm_source=typeahead&amp;amp;utm_medium=newquestion&amp;amp;utm_campaign=no_votes_sort_relev but it did not receive an accepted answer&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:15:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320322#M95730</guid>
      <dc:creator>chinchin96</dc:creator>
      <dc:date>2020-09-29T14:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two record sets where a distinct value matches (without using join)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320323#M95731</link>
      <description>&lt;P&gt;Shouldn't either line 1 or line 8 be "for recipient"?&lt;/P&gt;</description>
      <pubDate>Sun, 28 May 2017 00:14:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320323#M95731</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2017-05-28T00:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two record sets where a distinct value matches (without using join)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320324#M95732</link>
      <description>&lt;P&gt;Oops.  You're right @rich7177. Just updated it. &lt;/P&gt;</description>
      <pubDate>Sun, 28 May 2017 00:47:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320324#M95732</guid>
      <dc:creator>chinchin96</dc:creator>
      <dc:date>2017-05-28T00:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two record sets where a distinct value matches (without using join)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320325#M95733</link>
      <description>&lt;P&gt;How about this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myindex source="source1" OR source="source2"  "for recipient" 
| extract pairdelim="|;,", kvdelim="=:", auto=f
| rex field=_raw "event (?&amp;lt;eventid&amp;gt;.(\w+))" 
| search eventid !="" 
| rex field=_raw "(?&amp;lt;username&amp;gt;\s......$)" 
| rex field=_raw "card (?&amp;lt;cardnum&amp;gt;.(\w+))"
| eval timestmap=if(isnotnull(username),_time,null())
| stats values(timestamp) as _time values(username) as username values(cardnum) as cardnum by eventid
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 28 May 2017 04:44:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320325#M95733</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-05-28T04:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two record sets where a distinct value matches (without using join)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320326#M95734</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myindex (source="source1" OR source="source2")  ("for recipient" OR  "for event")
| extract pairdelim="|;,", kvdelim="=:", auto=f  
| rex "(?&amp;lt;username&amp;gt;\s......$)" 
| rex "card (?&amp;lt;cardnum&amp;gt;.(\w+))"  
| search username!=""  OR cardnum !="" 
| rex "event (?&amp;lt;eventid&amp;gt;.(\w+))" 
| search eventid !="" 
| stats min(_time) AS Time values(username) AS username values(cardnum) AS cardnum BY eventid
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 28 May 2017 21:19:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320326#M95734</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-05-28T21:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two record sets where a distinct value matches (without using join)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320327#M95735</link>
      <description>&lt;P&gt;Thanks @somesoni2! This worked (after noticing timestamp was mispelled on line 7. :-))  &lt;/P&gt;

&lt;P&gt;The only issue I saw is that for records in the final display that didn't have a username (not all records do), there was not a timestamp shown even though one exists. I changed isnotnull to isnull and it seemed to work. I then added a &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| table _time eventid username cardnum
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to the end to get the order presented in the question. &lt;/P&gt;

&lt;P&gt;So, while it all works now, I don't know that I could explain &lt;EM&gt;how&lt;/EM&gt;. I'd love to be able to use your method again in the future but don't know I can follow the logic. Can you help me understand it?&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2017 03:17:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320327#M95735</guid>
      <dc:creator>chinchin96</dc:creator>
      <dc:date>2017-05-29T03:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two record sets where a distinct value matches (without using join)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320328#M95736</link>
      <description>&lt;P&gt;Thanks @woodcock! This worked as well. Also had to add &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| table _time survey_uid partial_email  assigned_card
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to get the column order right.  So, much like @somesoni2, I love that your method works but I don't kno why. Can you walk me through the logic?&lt;/P&gt;

&lt;P&gt;Also, both your query and @somesoni2 seem to be pretty fast. Does Splunk have a preference between the two?&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2017 03:21:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320328#M95736</guid>
      <dc:creator>chinchin96</dc:creator>
      <dc:date>2017-05-29T03:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two record sets where a distinct value matches (without using join)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320329#M95737</link>
      <description>&lt;P&gt;The general approach to a merge is to pull in all the events with a single main search; that is why I put the &lt;CODE&gt;("for recipient" OR  "for event")&lt;/CODE&gt; there.  Then you can do a &lt;CODE&gt;stats .. BY JoiningField&lt;/CODE&gt; to do the merge.  You just need to decide what it is that you need to keep from the merge.  doing &lt;CODE&gt;stats values(*) AS * BY JoiningField&lt;/CODE&gt; gets you pretty much everything and you can trim down from that but in your case you knew exactly what you needed so I worked with that.&lt;/P&gt;

&lt;P&gt;I suspect that mine is faster because the other one has 2 &lt;CODE&gt;search&lt;/CODE&gt; passes but the only way to know for sure is to run each search on your data and use the &lt;CODE&gt;Job Inspector&lt;/CODE&gt; to see how long each one really takes.&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2017 14:33:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320329#M95737</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-05-29T14:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two record sets where a distinct value matches (without using join)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320330#M95738</link>
      <description>&lt;P&gt;Thank @woodcock! This explanation is very useful!&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2017 20:31:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-two-record-sets-where-a-distinct-value-matches-without/m-p/320330#M95738</guid>
      <dc:creator>chinchin96</dc:creator>
      <dc:date>2017-05-29T20:31:43Z</dc:date>
    </item>
  </channel>
</rss>

