{"action":"opened","issue":{"url":"https://api.github.com/repos/ankane/searchkick/issues/414","labels_url":"https://api.github.com/repos/ankane/searchkick/issues/414/labels{/name}","comments_url":"https://api.github.com/repos/ankane/searchkick/issues/414/comments","events_url":"https://api.github.com/repos/ankane/searchkick/issues/414/events","html_url":"https://github.com/ankane/searchkick/issues/414","id":64009676,"number":414,"title":"Order mixed with pagination yields correct block of records, sorted by ID","user":{"login":"totallymike","id":320778,"avatar_url":"https://avatars.githubusercontent.com/u/320778?v=3","gravatar_id":"","url":"https://api.github.com/users/totallymike","html_url":"https://github.com/totallymike","followers_url":"https://api.github.com/users/totallymike/followers","following_url":"https://api.github.com/users/totallymike/following{/other_user}","gists_url":"https://api.github.com/users/totallymike/gists{/gist_id}","starred_url":"https://api.github.com/users/totallymike/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/totallymike/subscriptions","organizations_url":"https://api.github.com/users/totallymike/orgs","repos_url":"https://api.github.com/users/totallymike/repos","events_url":"https://api.github.com/users/totallymike/events{/privacy}","received_events_url":"https://api.github.com/users/totallymike/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-24T14:30:30Z","updated_at":"2015-03-24T14:30:30Z","closed_at":null,"body":"Title pretty much states the problem.  I have a large collection that we'd like to sort by a timestamp and paginate.  Imagine it looks like this:\r\n\r\n```json\r\n[\r\n  {\"id\": 1, \"timestamp\": \"March 1, 2015\"},\r\n  {\"id\": 2, \"timestamp\": \"March 2, 2015\"},\r\n  {\"id\": 3, \"timestamp\": \"March 3, 2015\"},\r\n  {\"id\": 4, \"timestamp\": \"March 4, 2015\"},\r\n  {\"id\": 5, \"timestamp\": \"March 5, 2015\"}\r\n]\r\n```\r\n\r\nOf course the actual format of the data is different.  It's typed like that because I'm typing hypothetical data.  Pretend it's stored correctly.\r\n\r\nNow the issue is that if, say, I request the records paginated by blocks of two ordered by `\"timestamp\": \"desc\"`, it will give me something like this:\r\n\r\n```json\r\n[\r\n  {\"id\": 4, \"timestamp\": \"March 4, 2015\"},\r\n  {\"id\": 5, \"timestamp\": \"March 5, 2015\"}\r\n]\r\n```\r\n\r\nNote that it yields the correct collection of records, but ordered by `id`, rather than descending timestamp.\r\n\r\nIf my understanding is correct, this is because the list of records is fetched from ElasticSearch, and then the *actual* records are fetched from Postgres, with a query something like this:\r\n\r\n```sql\r\nSELECT * FROM my_records WHERE id IN [4, 5];\r\n```\r\n\r\nIs there a way, without manually reconstructing the SQL query to use the same ordering logic as the ES query, to request the data in the order one would expect it to be?  Perhaps I'm missing something entirely."}}