12

Can I search elasticsearch (version 2.3) and in the search query sort by more than 1 field? Right now i'm sorting by @timestamp and I would like to sort by hostname as well.

Thanks,

2 Answers 2

28

As the doc says, you can add one or more sort on specific fields like this:

"sort" : [
    { 
        "@timestamp" : "desc" 
    },  
    { 
        "hostname " : "desc" 
    }
]
Sign up to request clarification or add additional context in comments.

Comments

9
{
    "query": {
        "range": {
            "@timestamp": {
                "gte": "@timestamp",
                "lte": "@timestamp"
            }
        }
    },
    "from": 0,
    "size": 1000,
    "_source": [
        "@timestamp",
    ],
    "sort": [{
            "@timestamp": {
                "order": "desc"
            }
        },
        {
            "age": "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.