44

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)

3
  • thanks a lot Diego, please enter it as an answer so I can accept it! Commented Dec 15, 2012 at 19:08
  • BTW, anybody knows how to order by several fields, like anio, cuenta, subcuenta??? from que querystring Commented Dec 15, 2012 at 19:08
  • 3
    @opensas: Just add more sort parameters. They will be applied in order given in URI. Commented Feb 21, 2017 at 13:08

3 Answers 3

64

Try sort=anio:desc.

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

Sign up to request clarification or add additional context in comments.

2 Comments

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 ?
21

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

Comments

0

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

GET _cat/indices?s=index:desc

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.