<?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 Most recent event from each source? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97464#M25152</link>
    <description>&lt;P&gt;I'm looking for an efficient way to retrieve the single most recent event from each of about 2000 sources.&lt;/P&gt;

&lt;P&gt;It seems that something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source=prefix*  | stats first(_raw) as _raw by source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;scans a lot of events.&lt;/P&gt;

&lt;P&gt;Is there a better way?&lt;/P&gt;

&lt;P&gt;Yoel&lt;/P&gt;</description>
    <pubDate>Thu, 12 Jul 2012 18:12:11 GMT</pubDate>
    <dc:creator>yoeljacobsen</dc:creator>
    <dc:date>2012-07-12T18:12:11Z</dc:date>
    <item>
      <title>Most recent event from each source?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97464#M25152</link>
      <description>&lt;P&gt;I'm looking for an efficient way to retrieve the single most recent event from each of about 2000 sources.&lt;/P&gt;

&lt;P&gt;It seems that something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source=prefix*  | stats first(_raw) as _raw by source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;scans a lot of events.&lt;/P&gt;

&lt;P&gt;Is there a better way?&lt;/P&gt;

&lt;P&gt;Yoel&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 18:12:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97464#M25152</guid>
      <dc:creator>yoeljacobsen</dc:creator>
      <dc:date>2012-07-12T18:12:11Z</dc:date>
    </item>
    <item>
      <title>Re: Most recent event from each source?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97465#M25153</link>
      <description>&lt;P&gt;Have a look at the &lt;CODE&gt;metadata&lt;/CODE&gt; command.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| metadata type=sources
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;UPDATE: So, to get the actual event, you could still use &lt;CODE&gt;metadata&lt;/CODE&gt;, but in a subsearch that feeds the outer search with specific info on where/when to look for events. I messed around a bit to get a search that's working. For clarity I can also show what did NOT work &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[| metadata type=sources | rename lastTime as _time | fields _time source]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The idea here was to get output from the subsearch like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;( ( _time=1341991627 AND source="source1" ) OR ( _time=1342119251 AND source="source2" ) OR ([...]))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However the problem is that &lt;CODE&gt;_time&lt;/CODE&gt; is considered to be an internal field, and as such won't get picked up by the &lt;CODE&gt;format&lt;/CODE&gt; command that is implicitly run by the subsearch. So the output will only contain the &lt;CODE&gt;source&lt;/CODE&gt; parts.&lt;/P&gt;

&lt;P&gt;However using a clever (or well...you be the judge of that) hack we can get the output we want anyway, by creating a field called &lt;CODE&gt;query&lt;/CODE&gt; which will contain the &lt;CODE&gt;_time&lt;/CODE&gt; filtering string. &lt;CODE&gt;query&lt;/CODE&gt; is a special field whose value is returned from the subsearch as-is rather than Splunk adding "query=" before it.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[| metadata type=sources | eval query="_time=".lastTime | fields source query]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should create a search filter that searches on a number of &lt;CODE&gt;source&lt;/CODE&gt;/&lt;CODE&gt;_time&lt;/CODE&gt; pairs as shown above. Because multiple events from a source could potentially occur within the same second, you might still need to add a &lt;CODE&gt;| dedup source&lt;/CODE&gt; at the end of the outer search to make sure you only get one event per source. I hope this gives you what you were looking for.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 18:20:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97465#M25153</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-07-12T18:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Most recent event from each source?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97466#M25154</link>
      <description>&lt;P&gt;If you're wanting to get the actual indexed 'event', that will be how you do it.  If you just want to know when the last event occurred for a source you could do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| metadata type=sources | search source="*prefix*" | convert ctime(lastTime) as timestamp | sort - lastTime
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Jul 2012 18:30:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97466#M25154</guid>
      <dc:creator>Lamar</dc:creator>
      <dc:date>2012-07-12T18:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: Most recent event from each source?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97467#M25155</link>
      <description>&lt;P&gt;Thanks but I  would like the raw events, not meta data on the sources.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 18:32:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97467#M25155</guid>
      <dc:creator>yoeljacobsen</dc:creator>
      <dc:date>2012-07-12T18:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: Most recent event from each source?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97468#M25156</link>
      <description>&lt;P&gt;Unfortunately it seems my initial method scans all the events over the time range.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 18:37:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97468#M25156</guid>
      <dc:creator>yoeljacobsen</dc:creator>
      <dc:date>2012-07-12T18:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: Most recent event from each source?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97469#M25157</link>
      <description>&lt;P&gt;It would because you're inspecting the raw events as opposed to the metadata of your events.  The way that both Ayn and myself shows is just for practical timing purposes.&lt;/P&gt;

&lt;P&gt;Help us understand what problem you're trying to solve and we may be able to find a better way.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 18:50:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97469#M25157</guid>
      <dc:creator>Lamar</dc:creator>
      <dc:date>2012-07-12T18:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: Most recent event from each source?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97470#M25158</link>
      <description>&lt;P&gt;I would like to have an external system that caches a "snapshot" of a group of sources. The cache will serve  hundreds of  request per second for some field values. For my purpose I only need the last event from each source but I would like to update the cache every few minutes.. I'm looking for a way to update this cache as efficiently as possible. As this still in design, I'm open for suggestions (such as using multiple indexes etc).&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 19:16:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97470#M25158</guid>
      <dc:creator>yoeljacobsen</dc:creator>
      <dc:date>2012-07-12T19:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Most recent event from each source?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97471#M25159</link>
      <description>&lt;P&gt;Updated my answer in an attempt to solve what I think you want to accomplish.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 19:26:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97471#M25159</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-07-12T19:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: Most recent event from each source?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97472#M25160</link>
      <description>&lt;P&gt;Very slick Ayn.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 19:36:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97472#M25160</guid>
      <dc:creator>Lamar</dc:creator>
      <dc:date>2012-07-12T19:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: Most recent event from each source?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97473#M25161</link>
      <description>&lt;P&gt;Brilliant!&lt;/P&gt;

&lt;P&gt;I wonder how will it scale for &amp;gt;1000 source. The subsearch will create a very large filter (although far from maxout max value of 10500).&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 19:59:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Most-recent-event-from-each-source/m-p/97473#M25161</guid>
      <dc:creator>yoeljacobsen</dc:creator>
      <dc:date>2012-07-12T19:59:28Z</dc:date>
    </item>
  </channel>
</rss>

