<?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 Sort command not sorting as expected in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Sort-command-not-sorting-as-expected/m-p/750355#M242297</link>
    <description>&lt;P&gt;The Splunk documentation says that the order rule is lexicographic. I am trying to sort the following values:&lt;BR /&gt;&lt;BR /&gt;| makeresults&lt;BR /&gt;| eval fruit="apple"&lt;BR /&gt;| append [ | makeresults | eval fruit="Banana" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="zebra" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="10" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="2" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="20" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="30" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="3" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="1" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="25" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="38" ]&lt;BR /&gt;| table fruit&lt;BR /&gt;| sort fruit&lt;BR /&gt;&lt;BR /&gt;The output I am getting is:&lt;BR /&gt;1, 2, 3, 10, 20, 25, 30, 38, Banana, apple, zebra&lt;BR /&gt;&lt;BR /&gt;I understand that Banana appears before apple because B&amp;lt;a. But what is up with string numerics?&lt;BR /&gt;&lt;BR /&gt;Shouldn't the order be: 1, 10, 2, 20, 25, 3, 30, 38, Banana, apple, zebra ?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Even the documentation says that between&amp;nbsp;&lt;SPAN&gt;10, 9, 70, 100 the sorted output should be 10, 100, 70, 90.&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="https://help.splunk.com/en/splunk-enterprise/search/spl-search-reference/9.2/search-commands/sort" target="_blank" rel="noopener"&gt;https://help.splunk.com/en/splunk-enterprise/search/spl-search-reference/9.2/search-commands/sort&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 23 Jul 2025 19:50:39 GMT</pubDate>
    <dc:creator>CyberAar</dc:creator>
    <dc:date>2025-07-23T19:50:39Z</dc:date>
    <item>
      <title>Sort command not sorting as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-command-not-sorting-as-expected/m-p/750355#M242297</link>
      <description>&lt;P&gt;The Splunk documentation says that the order rule is lexicographic. I am trying to sort the following values:&lt;BR /&gt;&lt;BR /&gt;| makeresults&lt;BR /&gt;| eval fruit="apple"&lt;BR /&gt;| append [ | makeresults | eval fruit="Banana" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="zebra" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="10" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="2" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="20" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="30" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="3" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="1" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="25" ]&lt;BR /&gt;| append [ | makeresults | eval fruit="38" ]&lt;BR /&gt;| table fruit&lt;BR /&gt;| sort fruit&lt;BR /&gt;&lt;BR /&gt;The output I am getting is:&lt;BR /&gt;1, 2, 3, 10, 20, 25, 30, 38, Banana, apple, zebra&lt;BR /&gt;&lt;BR /&gt;I understand that Banana appears before apple because B&amp;lt;a. But what is up with string numerics?&lt;BR /&gt;&lt;BR /&gt;Shouldn't the order be: 1, 10, 2, 20, 25, 3, 30, 38, Banana, apple, zebra ?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Even the documentation says that between&amp;nbsp;&lt;SPAN&gt;10, 9, 70, 100 the sorted output should be 10, 100, 70, 90.&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="https://help.splunk.com/en/splunk-enterprise/search/spl-search-reference/9.2/search-commands/sort" target="_blank" rel="noopener"&gt;https://help.splunk.com/en/splunk-enterprise/search/spl-search-reference/9.2/search-commands/sort&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 19:50:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-command-not-sorting-as-expected/m-p/750355#M242297</guid>
      <dc:creator>CyberAar</dc:creator>
      <dc:date>2025-07-23T19:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: Sort command not sorting as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-command-not-sorting-as-expected/m-p/750357#M242298</link>
      <description>&lt;P&gt;When I add&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval type=typeof(fruit)&lt;/LI-CODE&gt;&lt;P&gt;to the query the results say the numbers are indeed numbers rather than strings.&amp;nbsp; That would explain the sort.&lt;/P&gt;&lt;P&gt;When I use&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| sort str(fruit)&lt;/LI-CODE&gt;&lt;P&gt;the results are in the expected lexicographical order.&lt;/P&gt;&lt;P&gt;FWIW, the docs do say "Numeric data is sorted as you would expect for numbers and the sort order is specified as ascending or descending."&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 20:06:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-command-not-sorting-as-expected/m-p/750357#M242298</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2025-07-23T20:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: Sort command not sorting as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-command-not-sorting-as-expected/m-p/750362#M242300</link>
      <description>&lt;P&gt;Interestingly, when using tostring() before the sort it still identifies as a number?!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="livehybrid_0-1753303733542.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/39740i91539BBD79310195/image-size/medium?v=v2&amp;amp;px=400" role="button" title="livehybrid_0-1753303733542.png" alt="livehybrid_0-1753303733542.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only way I can make it sort as a string is using | sort str(fruit) as&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&amp;nbsp; mentioned.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":glowing_star:"&gt;🌟&lt;/span&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Did this answer help you?&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;If so, please consider:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Adding karma to show it was useful&lt;/LI&gt;&lt;LI&gt;Marking it as the solution if it resolved your issue&lt;/LI&gt;&lt;LI&gt;Commenting if you need any clarification&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Your feedback encourages the volunteers in this community to continue contributing&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2025 20:49:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-command-not-sorting-as-expected/m-p/750362#M242300</guid>
      <dc:creator>livehybrid</dc:creator>
      <dc:date>2025-07-23T20:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: Sort command not sorting as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-command-not-sorting-as-expected/m-p/750600#M242385</link>
      <description>&lt;P&gt;thanks for response !&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/170906"&gt;@livehybrid&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&amp;nbsp; - yes, the documentation does mention that numerics will be sorted as numbers. I am confused because I thought that by putting quotes around the numbers, they would automatically get appended as strings to the fruit field and not as numbers.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So is it right to conclude that even though I added double quotes for numbers while appending them, by default Splunk does not take it as a string? Explicit type conversion is required as an additional step?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jul 2025 23:07:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-command-not-sorting-as-expected/m-p/750600#M242385</guid>
      <dc:creator>CyberAar</dc:creator>
      <dc:date>2025-07-28T23:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: Sort command not sorting as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-command-not-sorting-as-expected/m-p/750640#M242390</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/170906"&gt;@livehybrid&lt;/a&gt;&amp;nbsp;noted, explicit type conversion does not make a difference here.&amp;nbsp; If you need numbers sorted as strings then you must use the &lt;FONT face="courier new,courier"&gt;str&lt;/FONT&gt; operator.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jul 2025 12:57:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-command-not-sorting-as-expected/m-p/750640#M242390</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2025-07-29T12:57:18Z</dc:date>
    </item>
  </channel>
</rss>

