# How can I change the sort order of search results?

**URL:** https://community.swiftype.com/t/how-can-i-change-the-sort-order-of-search-results/61
**Category:** Setup & Indexing
**Created:** [December 21, 2015, 10:15pm UTC](https://community.swiftype.com/t/how-can-i-change-the-sort-order-of-search-results/61 "2015-12-21T22:15:03Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex019/uploads/swiftype/original/1X/fd652d1735c60057fa71c371375511028f9a1832.png) [@system](https://community.swiftype.com/u/system)
#### Post date: [December 21, 2015, 10:15pm UTC](https://community.swiftype.com/t/how-can-i-change-the-sort-order-of-search-results/61/1 "2015-12-21T22:15:04Z")

</div>

> **I would like my search results to be sorted differently from the default. How can I do this?**

By default, Swiftype sorts results by relevance so that the most likely search results are at the top.

You can change how relevance is determined by boosting a field’s weight. For example, if you use a Swiftype crawler-based search engine and you want to increase the importance of matches in the **title** field, add a boost to the **page** DocumentType:

```auto
{
  "q": "example",
  "search_fields": {"page": ["title^3", "sections", "body"]
 }

```

Keep in mind that if you do not specify **`search_fields`** Swiftype will use all **`string`** and **`text`** fields defined in your **Document Type**. When specifying boosted fields, it’s important to include all the other fields you also want to be searched – otherwise matches in those fields won’t be included in the results. (For a list of all the fields in the **page** DocumentType, [see the documentation](https://swiftype.com/documentation/crawler#schema).)

Read more about [field weights](https://swiftype.com/documentation/searching#field_weights).

Another way to change the relevance calculation is to apply a [functional boost](https://swiftype.com/documentation/searching#functional_boosts). Functional boosts can only be applied to numeric fields, so this is mostly useful for customers who are indexing their own content with the Swiftype API instead of using the Swiftype web crawler.

You can also change the order of results by specifying a **sort\_field** and **sort\_direction**. This will override the default relevance based sort. All results returned will match the search, but the results will be sorted in the order you specify.

For example, if you have a DocumentType named **`posts`** that has a date field named **`timestamp`** , you can sort the results so the newest documents are returned first:

```auto
{
  "q": "example",
  "sort_field": {"posts": "timestamp"},
  "sort_direction": {"posts": "desc"}
}

```

Note that you can only sort on **`date`** , **`enum`** , **`float`** , and **`integer`** fields.

To learn more about sorting you can refer to [this documentation](https://swiftype.com/documentation/searching#sorting).
