<?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 stats as a filtered self join? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-stats-as-a-filtered-self-join/m-p/432974#M123688</link>
    <description>&lt;P&gt;Since all of your sources are already indexed, I think it should be as simple as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=common_index sourcetype=common_sourcetype ((EventName=First somethingElse=whatever) or EventName=Second)
| stats values(keyField) as keyField by GroupID, EventName
| fields - GroupID
| mvexpand keyField
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You may also want to dedup the table, but technically, I think this should give you the same result.&lt;/P&gt;</description>
    <pubDate>Tue, 28 Aug 2018 17:39:33 GMT</pubDate>
    <dc:creator>nrohbock</dc:creator>
    <dc:date>2018-08-28T17:39:33Z</dc:date>
    <item>
      <title>How to use stats as a filtered self join?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-stats-as-a-filtered-self-join/m-p/432973#M123687</link>
      <description>&lt;P&gt;I have groups of events that have the same &lt;CODE&gt;GroupID&lt;/CODE&gt; field.  &lt;/P&gt;

&lt;P&gt;For events matching given criteria I need to find another event with predefined &lt;CODE&gt;EventName&lt;/CODE&gt;  from the same group and then &lt;CODE&gt;table&lt;/CODE&gt; together certain fields from both events .&lt;/P&gt;

&lt;P&gt;Using &lt;CODE&gt;join&lt;/CODE&gt; it will be something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=common_index sourcetype=common_sourcetype EventName=First somethingElse=whatever
| join GroupID [search index=common_index sourcetype=common_sourcetype EventName=Second | table GoupId keyField]
| table EventName keyField 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What would be the same type of query with &lt;CODE&gt;stats&lt;/CODE&gt;?&lt;/P&gt;

&lt;P&gt;I do not know how to do something like &lt;CODE&gt;earliest(EventName==value)&lt;/CODE&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 17:12:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-stats-as-a-filtered-self-join/m-p/432973#M123687</guid>
      <dc:creator>pm771</dc:creator>
      <dc:date>2018-08-28T17:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to use stats as a filtered self join?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-stats-as-a-filtered-self-join/m-p/432974#M123688</link>
      <description>&lt;P&gt;Since all of your sources are already indexed, I think it should be as simple as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=common_index sourcetype=common_sourcetype ((EventName=First somethingElse=whatever) or EventName=Second)
| stats values(keyField) as keyField by GroupID, EventName
| fields - GroupID
| mvexpand keyField
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You may also want to dedup the table, but technically, I think this should give you the same result.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 17:39:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-stats-as-a-filtered-self-join/m-p/432974#M123688</guid>
      <dc:creator>nrohbock</dc:creator>
      <dc:date>2018-08-28T17:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to use stats as a filtered self join?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-stats-as-a-filtered-self-join/m-p/432975#M123689</link>
      <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;

&lt;P&gt;My task is to select certain events and then match them (and only them) to another event from the same group.&lt;/P&gt;

&lt;P&gt;Then I need &lt;CODE&gt;EvenName&lt;/CODE&gt; from the &lt;STRONG&gt;first&lt;/STRONG&gt; search and &lt;CODE&gt;keyField&lt;/CODE&gt; from the &lt;STRONG&gt;second&lt;/STRONG&gt;. &lt;/P&gt;

&lt;P&gt;Your code is pulling 2nd event regardless if the 1st satisfied the criteria.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 17:57:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-stats-as-a-filtered-self-join/m-p/432975#M123689</guid>
      <dc:creator>pm771</dc:creator>
      <dc:date>2018-08-28T17:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to use stats as a filtered self join?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-stats-as-a-filtered-self-join/m-p/432976#M123690</link>
      <description>&lt;P&gt;Sorry for the false lead.  I hope this is more helpfull.&lt;/P&gt;

&lt;P&gt;index=common_index sourcetype=common_sourcetype &lt;BR /&gt;
| streamstats count as order by GroupID &lt;BR /&gt;
| eval myEventName=if(order=1 and somethingElse=whatever, EventName, null()), myKeyField=if(order=2, keyField, null()) &lt;BR /&gt;
| stats values(myEventName) as EventName, values(myKeyField) as keyField by GroupID&lt;BR /&gt;
| search EventName=* keyField=*&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:04:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-stats-as-a-filtered-self-join/m-p/432976#M123690</guid>
      <dc:creator>nrohbock</dc:creator>
      <dc:date>2020-09-29T21:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to use stats as a filtered self join?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-stats-as-a-filtered-self-join/m-p/432977#M123691</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=common_index sourcetype=common_sourcetype (EventName=First somethingElse=whatever) OR (EventName=Second)
| eval EventNameToUse=if(EventName="First",EventName,null())
| stats dc(EventName) as reportedOnvalues(EventNameToUse) as EventName values(keyField) as keyField by GroupId
| where reportedOn=2
 | table EventName keyField  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Aug 2018 21:53:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-stats-as-a-filtered-self-join/m-p/432977#M123691</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-08-28T21:53:30Z</dc:date>
    </item>
  </channel>
</rss>

