<?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 do a stable sort? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232594#M69008</link>
    <description>&lt;P&gt;Need to test it but try to put the string as macro.&lt;/P&gt;</description>
    <pubDate>Sat, 05 Mar 2016 01:17:07 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2016-03-05T01:17:07Z</dc:date>
    <item>
      <title>How can I do a stable sort?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232586#M69000</link>
      <description>&lt;P&gt;I am trying to create a view that merges log records from various files, ordered by their timestamps.  This works nicely, except when there are entries with the same timestamp.  Can Splunk do a stable sort?&lt;/P&gt;

&lt;P&gt;From &lt;A href="https://en.wikipedia.org/wiki/Category:Stable_sorts:"&gt;https://en.wikipedia.org/wiki/Category:Stable_sorts:&lt;/A&gt;&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Stable sorting algorithms maintain the relative order of records with equal keys (i.e. values). That is, a sorting algorithm is stable if whenever there are two records R and S with the same key and with R appearing before S in the original list, R will appear before S in the sorted list.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 04 Mar 2016 20:57:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232586#M69000</guid>
      <dc:creator>jdjdjdjd</dc:creator>
      <dc:date>2016-03-04T20:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a stable sort?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232587#M69001</link>
      <description>&lt;P&gt;Can you provide the query that you're currently using?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2016 23:15:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232587#M69001</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-03-04T23:15:00Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a stable sort?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232588#M69002</link>
      <description>&lt;P&gt;My query looks like this:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=*mysite*  29f91eb36868446fbf1ae667c895923c | sort _time&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2016 23:21:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232588#M69002</guid>
      <dc:creator>jdjdjdjd</dc:creator>
      <dc:date>2016-03-04T23:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a stable sort?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232589#M69003</link>
      <description>&lt;P&gt;Can post examples (just the timestamp) where you think Splunk is not doing a stable sort? IMO, for events with same timestamp, Splunk will keep them in the order they were retrieved by Splunk (non-chronological order).&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2016 23:34:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232589#M69003</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-03-04T23:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a stable sort?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232590#M69004</link>
      <description>&lt;P&gt;Here's an example.  I'm exporting from Splunk in raw format, that's where I'm seeing the problem.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"ts":"2016-03-02T17:28:52.461",
{"ts":"2016-03-02T17:28:52.461",
{"ts":"2016-03-02T17:28:52.461",
{"ts":"2016-03-02T17:28:52.461",
{"ts":"2016-03-02T17:28:52.461",
{"ts":"2016-03-02T17:28:52.461",
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Mar 2016 23:39:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232590#M69004</guid>
      <dc:creator>jdjdjdjd</dc:creator>
      <dc:date>2016-03-04T23:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a stable sort?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232591#M69005</link>
      <description>&lt;P&gt;On closer examination, I'm seeing the same results even without &lt;CODE&gt;sort&lt;/CODE&gt;, so it seems as if Splunk is retrieving my records in the "wrong order" when they have the same timestamp.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2016 23:48:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232591#M69005</guid>
      <dc:creator>jdjdjdjd</dc:creator>
      <dc:date>2016-03-04T23:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a stable sort?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232592#M69006</link>
      <description>&lt;P&gt;So the order Splunk provides for the data with same timestamp is not correct? &lt;BR /&gt;
I'm not super sure about requirement here, but my guess will that you want to events in increasing order of _time, where Splunk shows events in decreasing order of _time. If you just want to reverse the order, Splunk provides a command &lt;CODE&gt;reverse&lt;/CODE&gt;, that will do exactly the same.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=*mysite* 29f91eb36868446fbf1ae667c895923c | reverse
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If that's not what you want, try this dirty workaround&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=*mysite* 29f91eb36868446fbf1ae667c895923c | streamstats count as rank by _time | sort _time -rank | fields - rank
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Mar 2016 23:51:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232592#M69006</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-03-04T23:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a stable sort?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232593#M69007</link>
      <description>&lt;P&gt;You are a wizard!  The dirty workaround looks like the answer.  Can you post this as an answer rather than a comment?&lt;/P&gt;

&lt;P&gt;Is there a way to encapsulate this so that I don't have to copy and paste it each time?&lt;/P&gt;</description>
      <pubDate>Sat, 05 Mar 2016 00:11:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232593#M69007</guid>
      <dc:creator>jdjdjdjd</dc:creator>
      <dc:date>2016-03-05T00:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a stable sort?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232594#M69008</link>
      <description>&lt;P&gt;Need to test it but try to put the string as macro.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Mar 2016 01:17:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-stable-sort/m-p/232594#M69008</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-03-05T01:17:07Z</dc:date>
    </item>
  </channel>
</rss>

