42

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)

Old Pro
  • 24,624
  • 7
  • 58
  • 106
opensas
  • 60,462
  • 79
  • 252
  • 386

3 Answers3

63

Try sort=anio:desc.

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

Diego Basch
  • 12,764
  • 2
  • 29
  • 24
  • Godd Job Buddy,. Do you know if we can use a GroupBy in Query string ? Also i want to Count with GroupBy. is it possible ? – Punit Gajjar Jul 06 '17 at 09:29
  • 3
    Link seems broken, check https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-uri-request.html – Marcosaurios Dec 17 '21 at 16:10
18

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

Community
  • 1
  • 1
Vinay Vemula
  • 3,855
  • 1
  • 21
  • 24
0

A simple example of how to sort indices in Management -> Dev Tools:

GET _cat/indices?s=index:desc