Core
API v2.x
2

sort #

Sorts and returns elements contained in a list, a set of unique values or a sorted set.
By default, sorting is numeric and elements are compared by their value, interpreted as double precision floating point number.

[Redis documentation]


Query Syntax #

HTTP #

URL: http://kuzzle:7512/ms/_sort/<_id>
Method: POST
Body:
{
  // optional arguments
  "alpha": "[false|true]",
  "by": "<external key pattern>",
  "direction": "[ASC|DESC]",
  "get": ["pattern1", "pattern2", "..."],
  "limit": ["<offset>", "<count>"],
  "store": "<destination key>"
}

Other protocols #

{
  "controller": "ms",
  "action": "sort",
  "_id": "<key>",
  "body": {
    "alpha": "[false|true]",
    "by": "<external key pattern>",
    "direction": "[ASC|DESC]",
    "get": ["pattern1", "pattern2", "..."],
    "limit": ["<offset>", "<count>"],
    "store": "<destination key>"
  }
}

Arguments #

  • _id: list, set or sorted set key identifier

Body properties #

Optional: #

  • alpha: perform an alphanumerical sort instead of a numeric one
  • by: instead of sorting by values directly, sort by values contained in external keys, using a pattern completed by values of the list/set/sorted set to sort
  • direction: sort in ascendant or descendant order
  • get: instead of returning the sorted values directly, return the values contained in external keys, using patterns completed by the sorted values
  • limit: limit the result set to a range of matching elements (similar to SELECT LIMIT offset, count in SQL). Format: [<offset(int)>, <count(int)>]
  • store: instead of returning the result set, store it in a list at destination key

Response #

Returns the sorted elements.

{
  "requestId": "<unique request identifier>",
  "status": 200,
  "error": null,
  "controller": "ms",
  "action": "sort",
  "collection": null,
  "index": null,
  "result": [
    "sorted element1",
    "sorted element2",
    "..."
  ]
}