title: DynamoDB Not Sorting by Sort Key
body: <p>I'm following along in <a href="https://app.pluralsight.com/library/courses/aws-dynamodb-deep-dive" rel="nofollow noreferrer">Pluralsight's DynamoDB Deep Dive course</a> using the AWS console. I've created a "messages" table with the following items:</p>
  
  <p><a href="https://i.stack.imgur.com/Cmyq2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cmyq2.png" alt="all dyanmodb table items"></a></p>
  
  <p>When creating the table, the primary key was setup with a sort key:</p>
  
  <pre><code>Primary partition key:  |  userid (Number)
  Primary sort key:       |  timestamp (Number)
  </code></pre>
  
  <p>Also, a Local Secondary Index (LSI) was added with the rating attribute as the sort key:</p>
  
  <pre><code>Partition key:          |  userid (Number)
  Sort Key:               |  rating (Number)
  </code></pre>
  
  <p>After creating and adding <em>some</em> of the records, a Global Secondary Index (GSI) was added using the topicid &amp; rating attributes:</p>
  
  <pre><code>Partition key:          |  topicid (Number)
  Sort Key:               |  rating (Number)
  </code></pre>
  
  <p>When attempting to query using the GSI, and sort in descending order (by the rating sort key), the items are not in order:</p>
  
  <p><a href="https://i.stack.imgur.com/W6UDA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W6UDA.png" alt="querying by topic id, and items out of order"></a></p>
  
  <p>I believe I added some of the items prior to creating the GSI, and some of the items after.  All of the items have been in the table for at least 30 minutes at this point.</p>
  
  <p>According to the tutorial, the items should be sorted in order of the sort (rating) field. It appears I'm missing something obvious.</p>
  
  <hr>
  
  <p>Update:</p>
  
  <p>The UI in the console seems to have changed since the tutorial. In the tutorial, a previous version of the results have no sort indicators next to the attribute names as seen here:</p>
  
  <p><a href="https://i.stack.imgur.com/bfmxg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bfmxg.png" alt="old results table has no sort indicator next to attribute names"></a></p>
  
  <p>Now, each attribute in the results area shows a sort indicator, as shown previously, which seems to default to the primary partition key.</p>
  
  <p>Specifying sort in the query now seems to act as a secondary sort parameter after the sort selected in the results header.</p>
  
  <p>A follow up question: is there a way in the AWS Console for the results to use the query's sort instead of what was last selected in the result pane heading?</p>
  
  <p>Otherwise, you get the following unintuitive result when clicking "Start search" if the <code>rating</code> heading was previously clicked:</p>
  
  <p><a href="https://i.stack.imgur.com/a58cL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a58cL.png" alt="sort obeys heading rather than the query&#39;s sort parameter"></a></p>