search mobile facets autocomplete spellcheck crawler rankings weights synonyms analytics engage api customize documentation install setup technology content domains user history info home business cart chart contact email activate analyticsalt analytics autocomplete cart contact content crawling custom documentation domains email engage faceted history info install mobile person querybuilder search setup spellcheck synonyms weights engage_search_term engage_related_content engage_next_results engage_personalized_results engage_recent_results success add arrow-down arrow-left arrow-right arrow-up caret-down caret-left caret-right caret-up check close content conversions-small conversions details edit grid help small-info error live magento minus move photo pin plus preview refresh search settings small-home stat subtract text trash unpin wordpress x alert case_deflection advanced-permissions keyword-detection predictive-ai sso

Sort

Sort your results in an order other than document score.

Using sort will override the default relevance scoring method.

A special sorting field name is available, _score, to order by relevance.

If a sort parameter is not given, results will be ordered by descending relevance.

Type Sorting
text Yes, alphanumerically.
number Yes, numerically.
date Yes, historically.
geolocation No

Sorting

Sort on one field.

Example - Sorting alphanumerically by the title of the national park.
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
  "query": "everglade",
  "sort": {
    "title": "desc"
  }
}'

Example - Sorting alphanumerically by the title of the national park.
No Java example available, showing cURL
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
  "query": "everglade",
  "sort": {
    "title": "desc"
  }
}'

Example - Sorting alphanumerically by the title of the national park.
No Node example available, showing cURL
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
  "query": "everglade",
  "sort": {
    "title": "desc"
  }
}'

Example - Sorting alphanumerically by the title of the national park.
No Ruby example available, showing cURL
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
  "query": "everglade",
  "sort": {
    "title": "desc"
  }
}'

Example - Sorting alphanumerically by the title of the national park.
No Python example available, showing cURL
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
  "query": "everglade",
  "sort": {
    "title": "desc"
  }
}'

Example - Sorting alphanumerically by the title of the national park.
No Javascript example available, showing cURL
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
  "query": "everglade",
  "sort": {
    "title": "desc"
  }
}'

Sorting on Multiple Fields

Sort on multiple fields by using an array.

Example - Sorting by document score and tie-breaking by the title of the national park.
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
  "query": "everglade",
  "sort": [
    { "_score": "desc" },
    { "title": "desc" }
  ]
}'

Example - Sorting by document score and tie-breaking by the title of the national park.
No Java example available, showing cURL
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
  "query": "everglade",
  "sort": [
    { "_score": "desc" },
    { "title": "desc" }
  ]
}'

Example - Sorting by document score and tie-breaking by the title of the national park.
No Node example available, showing cURL
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
  "query": "everglade",
  "sort": [
    { "_score": "desc" },
    { "title": "desc" }
  ]
}'

Example - Sorting by document score and tie-breaking by the title of the national park.
No Ruby example available, showing cURL
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
  "query": "everglade",
  "sort": [
    { "_score": "desc" },
    { "title": "desc" }
  ]
}'

Example - Sorting by document score and tie-breaking by the title of the national park.
No Python example available, showing cURL
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
  "query": "everglade",
  "sort": [
    { "_score": "desc" },
    { "title": "desc" }
  ]
}'

Example - Sorting by document score and tie-breaking by the title of the national park.
No Javascript example available, showing cURL
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
  "query": "everglade",
  "sort": [
    { "_score": "desc" },
    { "title": "desc" }
  ]
}'

Errors

sortIf the field used to sort is not in the schema and is not _score.
If the sort JSON object has more than one key.

Stuck? Looking for help? Contact support or check out the App Search community forum!