# Sorting search results

**URL:** <https://discuss.elastic.co/t/sorting-search-results/19786>\
**Category:** Elasticsearch\
**Created:** [September 15, 2014, 1:01pm UTC](https://discuss.elastic.co/t/sorting-search-results/19786 "2014-09-15T13:01:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![matej\_zerovnik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matej_zerovnik/32/1280_2.png) [@matej\_zerovnik](https://discuss.elastic.co/u/matej_zerovnik)\
**Post date:** [September 15, 2014, 1:01pm UTC](https://discuss.elastic.co/t/sorting-search-results/19786/1 "2014-09-15T13:01:38Z")

</div>

Hello!

I'm trying to create a query, that would return the last(sorted by  
timestamp) 10 hits. I'm using logstash to parse and index my log files...

I tried 2 different queries:  
{  
"query" : {  
"filtered" : {  
"query": {"match" : {"user" : "abc"}},  
"query": {"match" : {"login\_succesful" : "true"}}  
}  
},  
"sort": [  
{ "timestamp": { "order": "desc" }}  
]  
}

and another one  
{  
"query" : {  
"bool" : {  
"must" : [  
{"match" : {"user" : "abc"}},  
{"match" : {"login\_succesful" : "true"}}  
]  
},  
"sort" : [  
{ "timestamp": { "order": "desc" }  
]  
}  
}

The first one lists all hits and doesn't sort and the 2nd one gives me  
an error saying "Parse Failure [No parser for element [timestamp]]]; }]".

What am I doing wrong?  
Should I define 'timestamp' field as date? Currently, all fields are  
mapped as "string, index, analyzed"...

Matej

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5416E332.3040009%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/5416E332.3040009%40gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:02am UTC](https://discuss.elastic.co/t/sorting-search-results/19786/2 "2017-07-06T01:02:19Z")

</div>


