# Sort by Timestamp with Curl Command

**URL:** https://discuss.elastic.co/t/sort-by-timestamp-with-curl-command/53690
**Category:** Elasticsearch
**Created:** [June 22, 2016, 4:38pm UTC](https://discuss.elastic.co/t/sort-by-timestamp-with-curl-command/53690 "2016-06-22T16:38:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![40at300](https://avatars.discourse-cdn.com/v4/letter/4/b4bc9f/32.png) [@40at300](https://discuss.elastic.co/u/40at300)
#### Post date: [June 22, 2016, 4:38pm UTC](https://discuss.elastic.co/t/sort-by-timestamp-with-curl-command/53690/1 "2016-06-22T16:38:59Z")

</div>

I get month old results when using the following query from curl. How can I sort by @timestamp and get the latest event?

curl 'localhost:9200/\*/\_search?q=field%3Aattribute&pretty=true' | grep times  
% Total % Received % Xferd Average Speed Time Time Time Current  
Dload Upload Total Spent Left Speed  
100 10058 100 10058 0 0 236k 0 --:--:-- --:--:-- --:--:-- 239k  
"@timestamp" : "2016-05-24T15:17:14.000Z",  
"timestamp" : "May 24 10:17:14",  
"@timestamp" : "2016-05-24T15:58:24.000Z",  
"timestamp" : "May 24 10:58:24",  
"@timestamp" : "2016-06-15T18:14:59.000Z",  
"timestamp" : "Jun 15 13:14:59",  
"@timestamp" : "2016-06-15T14:14:57.000Z",  
"timestamp" : "Jun 15 09:14:57",  
"@timestamp" : "2016-05-19T23:03:39.000Z",  
"timestamp" : "May 19 18:03:39",  
"@timestamp" : "2016-05-19T17:27:32.000Z",  
"timestamp" : "May 19 12:27:32",  
"@timestamp" : "2016-05-05T17:32:11.000Z",  
"timestamp" : "May 5 12:32:11",  
"@timestamp" : "2016-05-05T17:32:10.000Z",  
"timestamp" : "May 5 12:32:10",  
"@timestamp" : "2016-05-05T16:13:54.000Z",  
"timestamp" : "May 5 11:13:54",  
"@timestamp" : "2016-05-09T19:08:24.000Z",  
"timestamp" : "May 9 14:08:24",

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [June 22, 2016, 4:56pm UTC](https://discuss.elastic.co/t/sort-by-timestamp-with-curl-command/53690/2 "2016-06-22T16:56:20Z")

</div>

[Here](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html) are the docs for sort. You can also use it on the [uri](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-uri-request.html) (search that page for `sort`.) You'll likely get much better performance by limiting the result to a modern time range as well. On the url that looks like [this](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_ranges).

---

<div class="post-metadata">

### Author: ![40at300](https://avatars.discourse-cdn.com/v4/letter/4/b4bc9f/32.png) [@40at300](https://discuss.elastic.co/u/40at300)
#### Post date: [June 23, 2016, 7:36pm UTC](https://discuss.elastic.co/t/sort-by-timestamp-with-curl-command/53690/3 "2016-06-23T19:36:29Z")

</div>

When I use curl in the format above, is that using URI or URL?

Thanks.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 5, 2017, 10:40pm UTC](https://discuss.elastic.co/t/sort-by-timestamp-with-curl-command/53690/4 "2017-07-05T22:40:59Z")

</div>


