Skip to main content
Version: 1.1beta1

Filter syntax

Clarify defines it's own resource filter syntax, that is inspired by MongoDB. The filter syntax lets you construct advanced queries for any filed that's declared as filterable by the target resource.

Examples

Record with label "location" == "pier":

{ "labels.location": "pier" }

Records with ID "itemid-1" or "itemid-2":

{ "id": { "$in": ["itemid-1", "itemid-2"] } }

Records with name or description equal to "foo":

{ "$or": [{ "name": "foo" }, { "description": "foo" }] }

Records with name or description containing "foo":

{
"$or": [
{ "name": { "$regex": "foo" } },
{ "description": { "$regex": "foo" } }
]
}

Conjuction operators

OperatorUsageDescription
N/A{"a": "b", "b": "a"}Join queries of different field with implicit logical AND.
$or{"$or": [{"a": "b"}, {"a": "a"}]}Join two clauses with a logical OR conjunction.
$and{"$and": [{"a": "a"}, {"b": "c"}]}Join two clauses with a logical AND conjuction.

Compare operators

OperatorUsageDescription
N/A{"a": "foo"}Automatic; matches using equality for text and numeric fields, or matching any element on equality in an array field.
$ne{"a": {"$ne": "foo"}}Matches using negated equality.
$regex{"a": {"$regex": "fo[o]{1}"}}Matches all resources where the field value is match the specified regex. Works on string fields.
$in{"a": {"$in": ["b", "c"]}}Matches all resources where the field value is present in the specified list.
$nin{"a": {"$nin": ["a", "b"]}}Matches all resources where the field value is not present in the specified list.
$lt{"a": {"$lt": 10}}Matches all resources where the field value is less than the specified value. Works on sortable field.
$lte{"a": {"$lte": 10}}Matches all resources where the field value is less than or equal to the specified value. Works on sortable field.
$gt{"a": {"$gt": 10}}Matches all resources where the field value is greater than the specified value. Works on sortable field.
$gte{"a": {"$gte": 10}}Matches all resources where the field value is greater than or equal to the specified value. Works on sortable field.

Regex compare operator

The regex operator matches documents containing the field given as a regular expression. The syntax generally the same syntax used by Perl, Python and other languages. For more info see the rest-layer documentation and https://golang.org/s/re2syntax for the description of the syntax.