Skip to main content

sort

The sort parameter specifies how the results will be sorted on the response, and which properties will be used for sorting.

sort can be specified as either a single value (a property name), an array of values (when sorting by multiple properties), or an object.

By default, results will be ordered in ascending order (lowest to highest). The order can be specified using the object variant.

Sort Using a Single Property

The results can be sorted by the value of single property:

[{
"FindEntity": {
"with_class": "Person",
"sort": "name",
"results": {
"list": ["name"]
}
}
}]

Sort, specifiying the order

The results can be sorted by a value in the specified order:

[{
"FindEntity": {
"with_class": "Person",
"sort": {
"key": "name",
"order": "descending"
},
"results": {
"list": ["name"]
}
}
}]

Sort using an array of Objects

The results can be sorted by the value of multiple properties, in the specified order:

[{
"FindEntity": {
"with_class": "Person",
"sort": [{
"key": "name",
"order": "descending"
}, {
"key": "age",
"order": "ascending"
}],
"results": {
"list": ["name"]
}
}
}]

Sort Examples With Images

Single property

[{
"FindImage": {
"constraints": {
"year_captured": [">=", 1870]
},
"blobs": false,
"sort": "year_captured",
"results": {
"list": ["artist", "year_captured", "event"]
}
}
}]

Response:

[{
"FindImage": {
"entities": [{
"artist": "Alice",
"event": "April Festival",
"year_captured": 1874
}, {
"artist": "Alice",
"event": "April Festival",
"year_captured": 1875
}, {
"artist": "Bob",
"event": "June Festival",
"year_captured": 1875
}, {
"artist": "Alice",
"event": "April Festival",
"year_captured": 1875
}, {
"artist": "Bob",
"event": "April Festival",
"year_captured": 1876
}, {
"artist": "Alice",
"event": "June Festival",
"year_captured": 1876
}, {
"artist": "Bob",
"event": "April Festival",
"year_captured": 1876
}, {
"artist": "Bob",
"event": "April Festival",
"year_captured": 1876
}, {
"artist": "Alice",
"event": "June Festival",
"year_captured": 1876
}, {
"artist": "Bob",
"event": "April Festival",
"year_captured": 1876
}],
"returned": 10,
"status": 0
}
}]

Single property in descending order

[{
"FindImage": {
"constraints": {
"year_captured": [">=", 1870]
},
"blobs": false,
"sort": {
"key": "year_captured",
"order": "descending"
},
"results": {
"list": ["artist", "year_captured", "event"]
}
}
}]

Response:

[{
"FindImage": {
"entities": [{
"artist": "Bob",
"event": "April Festival",
"year_captured": 1876
}, {
"artist": "Alice",
"event": "June Festival",
"year_captured": 1876
}, {
"artist": "Bob",
"event": "April Festival",
"year_captured": 1876
}, {
"artist": "Bob",
"event": "April Festival",
"year_captured": 1876
}, {
"artist": "Alice",
"event": "June Festival",
"year_captured": 1876
}, {
"artist": "Bob",
"event": "April Festival",
"year_captured": 1876
}, {
"artist": "Alice",
"event": "April Festival",
"year_captured": 1875
}, {
"artist": "Bob",
"event": "June Festival",
"year_captured": 1875
}, {
"artist": "Alice",
"event": "April Festival",
"year_captured": 1875
}, {
"artist": "Alice",
"event": "April Festival",
"year_captured": 1874
}],
"returned": 10,
"status": 0
}
}]

Sorting using multiple properties:

[{
"FindImage": {
"constraints": {
"year_captured": [">=", 1870]
},
"blobs": false,
"sort": [{
"key": "year_captured",
"order": "descending"
}, {
"key": "artist",
"order": "ascending"
}],
"results": {
"list": ["artist", "year_captured", "event"]
}
}
}]

Response:

[{
"FindImage": {
"entities": [{
"artist": "Alice",
"event": "June Festival",
"year_captured": 1876
}, {
"artist": "Alice",
"event": "June Festival",
"year_captured": 1876
}, {
"artist": "Bob",
"event": "April Festival",
"year_captured": 1876
}, {
"artist": "Bob",
"event": "April Festival",
"year_captured": 1876
}, {
"artist": "Bob",
"event": "April Festival",
"year_captured": 1876
}, {
"artist": "Bob",
"event": "April Festival",
"year_captured": 1876
}, {
"artist": "Alice",
"event": "April Festival",
"year_captured": 1875
}, {
"artist": "Alice",
"event": "April Festival",
"year_captured": 1875
}, {
"artist": "Bob",
"event": "June Festival",
"year_captured": 1875
}, {
"artist": "Alice",
"event": "April Festival",
"year_captured": 1874
}],
"returned": 10,
"status": 0
}
}]