---
title: "Sorting content results"
slug: "sorting-content-results"
abstract: "Advanced example that shows you how to use the Sitecore Discover Search and Recommendation API to sort content results."
---
# Sorting content results

The following examples show different types of sorting and continue from the [querying product content example](https://doc.sitecore.com/discover/en/developers/discover-developer-guide/integrate-using-discover-rest-apis/integrate-using-the-search-and-recommendation-api/examples-of-advanced-search-and-recommendation-use-cases/querying-content.html#UUID-e550beba-520c-4966-e771-af94b61126dc_section-idm453834776276163287764365417 "Querying product content").

<details>
<summary><h2>Sorting by name alphabetically</h2></summary>

The following example shows you how to sort results by `name` in an ascending alphabetical order.

Here is the request:

```JSON
{
  "query": {
    "keyphrase": ["red"]
  },
  "n_item": 3,
  "content": {},
  "sort": {
    "type": "name",
    "order": "asc"
  }
}
```

Here is the response:

```JSON
{
  "ts": 1480977544,
  "rid": "response_id_150",
  "url": "/searchpage?keyphrase=red&sort=na39dC",
  "query2id": {
    "keyphrase": "keyphrase_id_red"
  },
  "content": {
    "product": {
      "value": [
        {"name": "jacket", "color": "red", "price": 80 },
        {"name": "pants", "price": 50, "category_name": ["red"] },
        {"name": "red dress", "price": 100}
      ]
    }
  },
  "n_item": 3,
  "total_item": 5,
  "page_number": 1,
  "total_page": 2
}
```

</details>

<details>
<summary><h2>Sorting by price from high to low</h2></summary>

The following example shows you how to sort the results by `price` in a descending order..

Here is the request:

```JSON
{
  "query": {
    "keyphrase": ["red"]
  },
  "n_item": 3,
  "content": {},
  "sort": {
    "type": "price",
    "order": "desc"
  }
}
```

Here is the response:

```JSON
{
  "ts": 1480977544,
  "rid": "response_id_151",
  "url": "/searchpage?keyphrase=red&sort=pas31pJ",
  "query2id": {
    "keyphrase": "keyphrase_id_red"
  },
  "content": {
    "product": {
      "value": [
        {"name": "red dress", "price": 100},
        {"name": "jacket", "color": "red", "price": 80 },
        {"name": "pants", "price": 50, "category_name": ["red"] }
      ]
    }
  },
  "n_item": 3,
  "total_item": 5,
  "page_number": 1,
  "total_page": 2
}
```

</details>

<details>
<summary><h2>Sorting by both price and name</h2></summary>

The following example shows you how to sort results using both sorting types, `price` and `name`. You first want to sort by `price` in an ascending order. If the price is the same, you next want to sort by `name` in an ascending order.

Here is the request:

```JSON
{
    "query": {
	"keyphrase": ["red"]
    },
    "n_item": 3,
    "content": {},
    "sort": {
    	"value": [{
        	"type": "price",
		"order": "desc"
	    },
	    {
		"type": "name",
		"order": "asc"
	    }
	]
    }
}
```

Here is the response:

```JSON
{
    "ts": 1480977544,
    "rid": "response_id_151",
    "url": "/searchpage?keyphrase=red&sort=pas31psdpDa",
    "query2id": {
        "keyphrase": "keyphrase_id_red"
    },
    "content": {
	"product": {
		"value": [{
			"name": "dress",
			"price": 100,
			"color": "red"
        	   },
		   {
		        "name": "red dress",
			"price": 100
		   },
		   {
			"name": "jacket",
			"color": "red",
			"price": 80
		   }
	        ]
	   }
	},
	"n_item": 3,
	"total_item": 5,
	"page_number": 1,
	"total_page": 2
}
```

</details>