title: elasticsearch sort by document id
body: <p>I have a simple index in elasticsearch and all my ids are manually added, i.e. I do not add documents with automatic string ids.</p>
  
  <p>Now the requirement is to get list of all documents page by page and sorted by the document id (i.e. _id)</p>
  
  <p>When I tried this with _id, it did not work. Then I looked for it on forums and found out this much that I have to use _uid for that. This actually works, although I have no clue how. But another problem is that the sorting is done as if the the _id is string. And it actually is a string. But I want the results as if the _id was a number.</p>
  
  <p>So there are two issues here:</p>
  
  <ol>
  <li><p>Why sorting does not work with _id and it does work with _uid</p></li>
  <li><p>Is there a way to get document ids sorted as numbers and not integers</p></li>
  </ol>
  
  <p>For e.g. if my doc ids are <code>1</code>, <code>2</code>, <code>3</code>, ..... , <code>55</code></p>
  
  <p>I am getting results in this order:</p>
  
  <p><code>1</code>, <code>10</code>, <code>11</code>, <code>12</code>, ... , <code>19</code>, <code>2</code>, <code>20</code>, ... so on</p>
  
  <p>While I would like to get the results in this order:</p>
  
  <p><code>1</code>, <code>2</code>, <code>3</code>, ... so on</p>
  
  <p>Any help is highly appreciated!</p>