<?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 can I get the latest event by a specific field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239642#M71183</link>
    <description>&lt;P&gt;Note, &lt;CODE&gt;latest()&lt;/CODE&gt; goes by the &lt;CODE&gt;_time&lt;/CODE&gt; value extracted from the event, not by what was last indexed. Usually _time is what you want though.&lt;/P&gt;</description>
    <pubDate>Sat, 26 Nov 2016 23:54:34 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2016-11-26T23:54:34Z</dc:date>
    <item>
      <title>How can I get the latest event by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239633#M71174</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have the following event data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;City,Date,Temp,Sky
New York,2016-11-10,20,Clear
New York,2016-11-10-19,Cloudy
San Francisco,2016-11-20,20,Clear
San Francisco,2016-11-19,18,Rain
Rome,2016-11-20,11,Rain
Rome,2016-11-19,10,Partly Cloudy
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I would like to do is get the latest event for each city, so I have results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;City,Date,Temp,Sky
New York,2016-11-10,20,Clear
San Francisco,2016-11-20,20,Clear
Rome,2016-11-20,11,Rain
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have tried&lt;/P&gt;

&lt;P&gt;stats first(City) by City&lt;/P&gt;

&lt;P&gt;But this just gives me a list that I cannot use.  Any help would be great!&lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;

&lt;P&gt;Andrew&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 16:08:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239633#M71174</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2016-11-26T16:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get the latest event by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239634#M71175</link>
      <description>&lt;P&gt;Hi andrewtrobec,&lt;BR /&gt;
you have to try with &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;stats latest(City) by City
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.5.0/SearchReference/CommonStatsFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/6.5.0/SearchReference/CommonStatsFunctions&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 16:59:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239634#M71175</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2016-11-26T16:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get the latest event by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239635#M71176</link>
      <description>&lt;P&gt;... | stats latest(_raw) latest(temp) latest(sky) by City&lt;/P&gt;

&lt;P&gt;Remove whatever you don't want.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 18:10:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239635#M71176</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-11-26T18:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get the latest event by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239636#M71177</link>
      <description>&lt;P&gt;Thanks!  What is the difference between your suggestion and what I was able to get working:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| dedup City
| table City, Date, Temp, Sky
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 18:18:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239636#M71177</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2016-11-26T18:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get the latest event by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239637#M71178</link>
      <description>&lt;P&gt;The &lt;CODE&gt;dedup&lt;/CODE&gt; command passes all fields to the next command whereas the &lt;CODE&gt;stats&lt;/CODE&gt; command only passes the stats it calculates and the fields following the &lt;CODE&gt;by&lt;/CODE&gt; keyword.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 20:53:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239637#M71178</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-11-26T20:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get the latest event by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239638#M71179</link>
      <description>&lt;P&gt;Additionally, &lt;CODE&gt;dedup&lt;/CODE&gt; goes by event order while &lt;CODE&gt;latest()&lt;/CODE&gt; goes by &lt;CODE&gt;_time&lt;/CODE&gt; order.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 21:16:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239638#M71179</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2016-11-26T21:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get the latest event by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239639#M71180</link>
      <description>&lt;P&gt;Thanks, that makes sense.  In my case I don't want all fields to pass on, so I suppose it's more efficient to use the &lt;CODE&gt;stats&lt;/CODE&gt; command.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 23:30:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239639#M71180</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2016-11-26T23:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get the latest event by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239640#M71181</link>
      <description>&lt;P&gt;Thanks for the clarification.  It that case I want to use &lt;CODE&gt;stats&lt;/CODE&gt; with &lt;CODE&gt;last&lt;/CODE&gt; since I want the last event (most recently indexed).&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 23:32:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239640#M71181</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2016-11-26T23:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get the latest event by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239641#M71182</link>
      <description>&lt;P&gt;Also note that first and last can be manipulated using sort prior to the stats command and therefore they are not meant for use when you want the latest or earliest event.  You really do want to insure your timeStamping is good and then use latest().  That's my final answer &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 23:48:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239641#M71182</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-11-26T23:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get the latest event by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239642#M71183</link>
      <description>&lt;P&gt;Note, &lt;CODE&gt;latest()&lt;/CODE&gt; goes by the &lt;CODE&gt;_time&lt;/CODE&gt; value extracted from the event, not by what was last indexed. Usually _time is what you want though.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 23:54:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-the-latest-event-by-a-specific-field/m-p/239642#M71183</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2016-11-26T23:54:34Z</dc:date>
    </item>
  </channel>
</rss>

