Skip to content
Home » Sort Query Elasticsearch

Sort Query Elasticsearch

  • by

GET /_search
{
“query”: {
“match”: {
“title”: “Elasticsearch”
}
},
“sort”: [
{
“date”: {
“order”: “desc”
}
}
]
}

This query will search for documents that contain the term “Elasticsearch” in the title field, and then sort the results by the date field in descending order.

The sort parameter in Elasticsearch takes a list of fields, followed by a direction (ascending or descending). In this case, the sort parameter is set to the date field, and the direction is set to desc. This means that the results will be sorted in descending order by the date field.

The date field in Elasticsearch is a special field that is used to store dates. When you index a document, you can specify the date field, and Elasticsearch will store the date in a format that can be sorted.

Leave a Reply

Your email address will not be published. Required fields are marked *

For Search, Content Management & Data Engineering Services

Get in touch with us