title: Elasticsearch shuffle index sorting
body: <p>Thanks in advance. I expose the situation first and in the end the solution.</p>
  
  <p>I have a collection of 2M documents with the following mapping:</p>
  
  <pre><code>{
     "image": {
        "properties": {
           "timestamp": {
              "type": "date",
              "format": "dateOptionalTime"
           },
           "title": {
              "type": "string"
           },
           "url": {
              "type": "string"
           }
        }
     }
  }
  </code></pre>
  
  <p>I have a webpage which paginates through all the documents with the following search:</p>
  
  <pre><code>{  
    "from":STARTING_POSITION_NUMBER,
    "size":15,
    "sort" : [
          { "_id" : {"order" : "desc"}}
      ],
    "query" : {
      "match_all": {}
     }
   }
  </code></pre>
  
  <p>And a hit looks like this(note that the _id value is a hash of the url to prevent duplicated documents):</p>
  
  <pre><code> {
      "_index": "images",
      "_type": "image",
      "_id": "2a750a4817bd1600",
      "_score": null,
      "_source": {
         "url": "http://test.test/test.jpg",
         "timestamp": "2014-02-13T17:01:40.442307",
         "title": "Test image!"
      },
      "sort": [
         null
      ]
   }
  </code></pre>
  
  <p>This works pretty well. The only problem I have is that the documents appear sorted chronologically (The oldest documents appear on the first page, and the ones indexed more recently on the last page), but I want them to appear on a random order. For example, page 10 should always show always the same N documents, but they don't have to appear sorted by the date.</p>
  
  <p>I though of something like sorting all the documents by their hash, which is kind of random and deterministic. How could I do it?</p>
  
  <p>I've searched on the docs and the sorting api just works for sorting the results, not the full index. If I don't find a solution I will pick documents randomly and index them on a separated collection.</p>
  
  <p>Thank you.</p>