<?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: Searching the latest event quickly in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201362#M58349</link>
    <description>&lt;P&gt;Well, &lt;CODE&gt;head&lt;/CODE&gt; restricts the number of results to the number you specify and Splunk discards the rest, so after receiving say 100 events, Splunk knows it doesn't have to look for more. &lt;CODE&gt;head&lt;/CODE&gt; shows the newest N events it encounters. (In the specified time frame.) There is also a &lt;CODE&gt;tail&lt;/CODE&gt; command that will give you the &lt;EM&gt;oldest&lt;/EM&gt; N events. The &lt;CODE&gt;tail&lt;/CODE&gt; command is therefore slower, since it has to churn through the entire result set first.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Sep 2016 09:31:39 GMT</pubDate>
    <dc:creator>echalex</dc:creator>
    <dc:date>2016-09-21T09:31:39Z</dc:date>
    <item>
      <title>Searching the latest event quickly</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201353#M58340</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;

&lt;P&gt;I would like to check if my firewall rules are used or not.&lt;BR /&gt;
For that, I'm doing something like that :&lt;BR /&gt;
index=firewall TERM(src=10.0.0.1) OR TERM(src=10.0.0.2) TERM(dst=10.0.0.3) TERM(port=12345) |  stats latest(_time)&lt;/P&gt;

&lt;P&gt;But it tooks a long time (on all events) ... However, it should not check buckets in the past, when it finds events 1 hour ago ...&lt;/P&gt;

&lt;P&gt;Do you have a tip for that ?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2016 09:48:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201353#M58340</guid>
      <dc:creator>laberthelemy</dc:creator>
      <dc:date>2016-09-20T09:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: Searching the latest event quickly</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201354#M58341</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;If I understand correctly, your main concern is slowness? Yes, if you just need the last event, you can use &lt;CODE&gt;head N&lt;/CODE&gt;, which will give you the &lt;CODE&gt;N&lt;/CODE&gt; latest events.&lt;/P&gt;

&lt;P&gt;Example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=firewall TERM(src=10.0.0.1) OR TERM(src=10.0.0.2) TERM(dst=10.0.0.3) TERM(port=12345) | head 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2016 12:31:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201354#M58341</guid>
      <dc:creator>echalex</dc:creator>
      <dc:date>2016-09-20T12:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: Searching the latest event quickly</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201355#M58342</link>
      <description>&lt;P&gt;If you only need the last hour then:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=firewall TERM(src=10.0.0.1) OR TERM(src=10.0.0.2) TERM(dst=10.0.0.3) TERM(port=12345)  earliest=-1h | stats latest(_time)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Sep 2016 12:53:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201355#M58342</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-09-20T12:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: Searching the latest event quickly</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201356#M58343</link>
      <description>&lt;P&gt;Thanks for your answers, but it's still long ...&lt;BR /&gt;
In fact, I don't know when is the last event, so I must search in "All time"&lt;BR /&gt;
And It seems that head 1 is evaluated after the full search.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2016 13:03:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201356#M58343</guid>
      <dc:creator>laberthelemy</dc:creator>
      <dc:date>2016-09-20T13:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: Searching the latest event quickly</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201357#M58344</link>
      <description>&lt;P&gt;If you don't know when the last event is, then &lt;CODE&gt;head&lt;/CODE&gt; will help you. Apparently your milage varies quite a bit, but for me &lt;CODE&gt;head&lt;/CODE&gt; seems to terminate the search very efficiently. I'm also searching over a "All time" in a huge index, but with &lt;CODE&gt;head&lt;/CODE&gt; it ends within a second.&lt;BR /&gt;
Did you see that you need to use &lt;CODE&gt;head&lt;/CODE&gt; &lt;STRONG&gt;before&lt;/STRONG&gt; you use &lt;CODE&gt;stats&lt;/CODE&gt;. In fact, I left out stats completely in my answer.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2016 14:39:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201357#M58344</guid>
      <dc:creator>echalex</dc:creator>
      <dc:date>2016-09-20T14:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: Searching the latest event quickly</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201358#M58345</link>
      <description>&lt;P&gt;In your example, if you need &lt;CODE&gt;stats&lt;/CODE&gt;, you would want to do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=firewall TERM(src=10.0.0.1) OR TERM(src=10.0.0.2) TERM(dst=10.0.0.3) TERM(port=12345) | head 1 |stats latest(_time)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Sep 2016 14:39:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201358#M58345</guid>
      <dc:creator>echalex</dc:creator>
      <dc:date>2016-09-20T14:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Searching the latest event quickly</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201359#M58346</link>
      <description>&lt;P&gt;See the comment I added to my original answer/&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2016 14:40:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201359#M58346</guid>
      <dc:creator>echalex</dc:creator>
      <dc:date>2016-09-20T14:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: Searching the latest event quickly</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201360#M58347</link>
      <description>&lt;P&gt;| head 1 | stats latest(_time)  is really efficient&lt;BR /&gt;
Thank you so much (even if I don't understand why we need head 1 &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 08:51:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201360#M58347</guid>
      <dc:creator>laberthelemy</dc:creator>
      <dc:date>2016-09-21T08:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: Searching the latest event quickly</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201361#M58348</link>
      <description>&lt;P&gt;I understand now : it was because I was searching on sourcetype instead of index. Sorry ...&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 08:55:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201361#M58348</guid>
      <dc:creator>laberthelemy</dc:creator>
      <dc:date>2016-09-21T08:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: Searching the latest event quickly</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201362#M58349</link>
      <description>&lt;P&gt;Well, &lt;CODE&gt;head&lt;/CODE&gt; restricts the number of results to the number you specify and Splunk discards the rest, so after receiving say 100 events, Splunk knows it doesn't have to look for more. &lt;CODE&gt;head&lt;/CODE&gt; shows the newest N events it encounters. (In the specified time frame.) There is also a &lt;CODE&gt;tail&lt;/CODE&gt; command that will give you the &lt;EM&gt;oldest&lt;/EM&gt; N events. The &lt;CODE&gt;tail&lt;/CODE&gt; command is therefore slower, since it has to churn through the entire result set first.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 09:31:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Searching-the-latest-event-quickly/m-p/201362#M58349</guid>
      <dc:creator>echalex</dc:creator>
      <dc:date>2016-09-21T09:31:39Z</dc:date>
    </item>
  </channel>
</rss>

