<?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: Query for two events based on intersection of common value - without using join in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-a-query-for-two-events-based-on-intersection-of/m-p/604065#M210134</link>
    <description>&lt;P&gt;Thank you, you gave me a great brainstorm!&lt;/P&gt;&lt;P&gt;Using your advice I set out to create some new fields and to manipulate them.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It made me notice that for Query1 I was inadvertently fetching multiple occurrences of events matching myEvent1.common_uid_field value rather than one representative event that is sufficient. I needed to constrain Query1 further.&lt;/P&gt;&lt;P&gt;By limiting Query1 to return only one event per common_uid_field I could now use one query for both event1 or event2 and count by common_uid_field. And only when count=2 does it mean the value is in both events.&lt;/P&gt;&lt;P&gt;My query is now of the form:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=myindex (event1) OR (event2)
| stats values(field_in_event1) AS ImportantField count by common_uid_field
| where count=2
| stats count BY ImportantField&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 01 Jul 2022 03:46:37 GMT</pubDate>
    <dc:creator>lmonahan</dc:creator>
    <dc:date>2022-07-01T03:46:37Z</dc:date>
    <item>
      <title>How to achieve a query for two events based on intersection of common value - without using join?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-a-query-for-two-events-based-on-intersection-of/m-p/604036#M210127</link>
      <description>&lt;P&gt;I want to run a query where:&lt;/P&gt;
&lt;P&gt;1. Query1 returns resultset1containing myEvent1.uid&lt;/P&gt;
&lt;P&gt;2. Query2 returns resultset2 containing myEvent2.uid which is a subset of the myEvent1uid values.&lt;/P&gt;
&lt;P&gt;3. Filter myEvent1 events and discard any that don't have a matching myEvent2.uid.&lt;/P&gt;
&lt;P&gt;This can be done easily with an inner join but the result2 dataset is larger than 50k so I cannot use a join.&lt;/P&gt;
&lt;P&gt;What I want is to do an &lt;EM&gt;inner join&lt;/EM&gt; without using &lt;EM&gt;join&lt;/EM&gt;!&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&amp;nbsp; (I'm also practicing not using &lt;EM&gt;join,&lt;/EM&gt; in general, but I really can't use join in this case.)&lt;/P&gt;
&lt;P&gt;Saw some other posts that use &lt;EM&gt;join&lt;/EM&gt; and other tricks and tried different solutions with &lt;EM&gt;coalesce()&lt;/EM&gt; and also creating a new fields but haven't figured out a way that worked.&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 22:24:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-a-query-for-two-events-based-on-intersection-of/m-p/604036#M210127</guid>
      <dc:creator>lmonahan</dc:creator>
      <dc:date>2022-06-30T22:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: Query for two events based on intersection of common value - without using join</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-a-query-for-two-events-based-on-intersection-of/m-p/604042#M210129</link>
      <description>&lt;P&gt;The typical approach would be to get your events to contain the common field - let's call it "uid" and do stats values(*) as * by uid.&lt;/P&gt;&lt;P&gt;The trick is to perform field shuffling (rename, conditional evals) to make fields from different types of events not overlap each other.&lt;/P&gt;&lt;P&gt;The easiest way is to do&lt;/P&gt;&lt;PRE&gt;search1&lt;BR /&gt;| append [ search2 ]&lt;BR /&gt;| stats values(*) as * by common_field&lt;/PRE&gt;&lt;P&gt;But this is ugly since it uses a subsearch and append.&lt;/P&gt;&lt;P&gt;More sophisticated (but tricky solution) is to use a single search to find both result sets and conditionally "remodel" the fields.&lt;/P&gt;&lt;PRE&gt;(Conditions1) OR (conditions2)&lt;BR /&gt;| eval field1=if(...)&lt;BR /&gt;| ...&lt;BR /&gt;| stats values(*) as * by common_field&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 21:15:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-a-query-for-two-events-based-on-intersection-of/m-p/604042#M210129</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-06-30T21:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: Query for two events based on intersection of common value - without using join</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-a-query-for-two-events-based-on-intersection-of/m-p/604065#M210134</link>
      <description>&lt;P&gt;Thank you, you gave me a great brainstorm!&lt;/P&gt;&lt;P&gt;Using your advice I set out to create some new fields and to manipulate them.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It made me notice that for Query1 I was inadvertently fetching multiple occurrences of events matching myEvent1.common_uid_field value rather than one representative event that is sufficient. I needed to constrain Query1 further.&lt;/P&gt;&lt;P&gt;By limiting Query1 to return only one event per common_uid_field I could now use one query for both event1 or event2 and count by common_uid_field. And only when count=2 does it mean the value is in both events.&lt;/P&gt;&lt;P&gt;My query is now of the form:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=myindex (event1) OR (event2)
| stats values(field_in_event1) AS ImportantField count by common_uid_field
| where count=2
| stats count BY ImportantField&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 01 Jul 2022 03:46:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-a-query-for-two-events-based-on-intersection-of/m-p/604065#M210134</guid>
      <dc:creator>lmonahan</dc:creator>
      <dc:date>2022-07-01T03:46:37Z</dc:date>
    </item>
  </channel>
</rss>

