Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elasticsearch set sort order using querystring

I have the following simple elastisearch query:

http://localhost:9200/apn/presupuesto/_search?q=subcuenta:penal&sort=anio 

And it works fine

Now I'm trying to order by anio desc. I tried with all these options:

...l&sort=anio desc  ...l&sort=-anio  ...l&sort=anio&order=desc 

But none of them seemed to work

How can I achieve it? (ideally, from the querystring, without having to use a more complex query)

like image 227
opensas Avatar asked Dec 15 '12 17:12

opensas


Video Answer


2 Answers

Try sort=anio:desc.

See search API - uri request for a list of parameters.

like image 168
Diego Basch Avatar answered Oct 06 '22 03:10

Diego Basch


To answer opensas question

elasticsearch set sort order using querystring

this feature is called as multilevel sorting.

Example query is

GET /_search {     "query" : {         "filtered" : {             "query":   { "match": { "tweet": "manage text search" }},             "filter" : { "term" : { "user_id" : 2 }}         }     },     "sort": [         { "date":   { "order": "desc" }},         { "_score": { "order": "desc" }}     ] } 

Order is important. Results are sorted by the first criterion first. Only results whose first sort value is identical will then be sorted by the second criterion, and so on. http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_sorting.html#_multilevel_sorting

like image 20
Vinay Vemula Avatar answered Oct 06 '22 02:10

Vinay Vemula