Skip to content

Search operators

When searching, Kamea provides a set of operators to allow you to have the most precise result.

These operators are separated in 2 categories: the values operators and the condition operators.

The values operators are, like their name state it, only applied to the value of the searched field. Whereas condition operators can be applied to the value or to another operator, be it "value" or "condition" operators.

List of available operators

Value operators:

  • $partialEq
  • $lt
  • $lte
  • $gt
  • $gte

Condition operators:

  • $not

Operators behavior

$partialEq

When using this operator, all the elements matching the value of the parameter "$partialEq" will be returned.

Ex: When searching devices with the following payload

{
    metadata: [{
        key: "key",
        value: {
            $partialEq: "search"
        }
    }]
}
The API will return all the devices having at least one metadata whose column "value" contains "search". So if a metadata have the value "search" it will be returned, because it's an exact match, and if a metadata have the value "searchValue" it will also be returned, because it contains the word "search".

Comparison operators

Kamea provides 4 comparison operators:

  • $lt "Lesser than": all the elements being strictly lesser than the value of the parameter "$lt" will be returned.
  • $lte "Lesser or equal": all the elements being lesser or equal than the value of the parameter "$lte" will be returned.
  • $gt "Greater than": all the elements being strictly greater than the value of the parameter "$gt" will be returned.
  • $gte "Greater or equal": all the elements being greater or equal than the value of the parameter "$gte" will be returned.

These 4 operators can be used the same way, like in the following example.

Ex: When searching devices with the following payload

{
    metadata: [{
        key: "key",
        value: {
            $lt: 10
        }
    }]
}
In the previous example, $lt can be replaced by any of the 4 comparison operators.

Note

Comparison operators can be used on any type of columns, not only number. For string and stringified boolean values, the comparison will be made on the alphabetical order.

$not

When using this operator, all the elements not matching than the value of the parameter "$not" will be returned.

Ex: When searching devices with the following payload

{
    metadata: [{
        key: "key",
        value: {
            $not: "search"
        }
    }]
}
The API will return all the devices having at least one metadata whose column "value" not matching the string "search.

The $not operator can also be used on other operator to have the opposite result.

Ex:

{
    metadata: [{
        key: "key",
        value: {
            $not: {
                $partialEq: "search"
            }
        }
    }]
}
In that case, the API will return all the devices NOT partially matching the string "search".

Searching on metadata and configurations

When searching on metadata or configurations, you can only use operator on the value property. The key or type will always be an exact match.

Note that any data type can be stored in metadata and configurations value column. So on the DB side, all the values will be stringified, they will be transformed back into the correct type when read by the API. This means that when filtering on these models, you have to remember that the underlying comparison will be done on strings, meaning that different data types can be compared as strings. For example, if you compare the boolean value true and the number 2 they will be compared as the strings "true" and "2".

Furthermore, because metadata and configurations can contain any data type, from small boolean to large JSON object, the search will not be as effective as for other fields. Therefore, if you have a lot of data, it is recommended to not search by too many metadata or configurations as it can bring performance issues.