Search code examples
elasticsearch

Elasticsearch query - sort by @timestamp and another field?


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,


Solution

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

    "sort" : [
        { 
            "@timestamp" : "desc" 
        },  
        { 
            "hostname " : "desc" 
        }
    ]