0

I have the following to return a count of documents 'grouped' by the document date. However, I would like the results to be displayed in date order. I tried the 'sort' option but this doesn't seem to work.

Any suggestions ?

GET /my_index/my_type/_search
{
    size: 0,
    sort: {
        date: {
            order: "desc"   
        }
    },
    aggs: {
        "docs_by_date": {
            "terms": {
                "field": "date",
                "size": 0
            }
        }
    }
}

1 Answer 1

1

If you want to sort buckets use following query:

GET /my_index/my_type/_search
{
size: 0,

aggs: {
    "docs_by_date": {
        "terms": {
            "field": "date",
            "size": 0,
            "order" : { "_term" : "asc" }
        }
    }
   }
}

Read this for more info

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

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.