- string
- number
- boolean
- object
- array
topK
documents may be returned.
Filter Syntax
A filter has a syntax that resembles SQL, which consists of operators on content keys and boolean operators to combine them. Assuming you have content like below:TypeSafe Filters (TypeScript)
In our TypeScript SDK, we support a typesafe way to build filters:Note that we passed
IndexContent
as a type parameter to the index
method. This allows the SDK to infer the type of the content, enabling type-safe filters.AND
and OR
operators to build complex filters.
Operators
Equals (=)
Theequals
operator filters content whose values are equal to the given literal.
It is applicable to string, number, and boolean values.
Not Equals (!=)
Thenot equals
operator filters content whose values are not equal to the given literal.
It is applicable to string, number, and boolean values.
Less Than (<)
Theless than
operator filters content whose values are less than the given literal.
It is applicable to number values.
Less Than or Equals (<=)
Theless than or equals
operator filters content whose values are less than or equal to the given literal.
It is applicable to number values.
Greater Than (>)
Thegreater than
operator filters content whose values are greater than the given literal.
It is applicable to number values.
Greater Than or Equals (>=)
Thegreater than or equals
operator filters content whose values are greater than or equal to the given literal.
It is applicable to number values.
Glob
Theglob
operator filters content whose values match with the given UNIX glob pattern.
It is applicable to string values.
It is a case sensitive operator.
The glob operator supports the following wildcards:
*
matches zero or more characters.?
matches exactly one character.[]
matches one character from the list[abc]
matches eithera
,b
, orc
.[a-z]
matches one of the range of characters froma
toz
.[^abc]
matches any one character other thana
,b
, orc
.[^a-z]
matches any one character other thana
toz
.
A
or B
.
Not Glob
Thenot glob
operator filters content whose values do not match with the given UNIX glob pattern.
It is applicable to string values.
It has the same properties with the glob operator.
For example, the filter below would only match with warehouse locations whose first character is anything other than A
.
In
Thein
operator filters content whose values are equal to any of the given literals.
It is applicable to string, number, and boolean values.
OR
boolean operator in between:
Not In
Thenot in
operator filters content whose values are not equal to any of the given literals.
It is applicable to string, number, and boolean values.
AND
boolean operator in between:
Contains
Thecontains
operator filters content whose values contain the given literal.
It is applicable to array values.
Not Contains
Thenot contains
operator filters content whose values do not contain the given literal.
It is applicable to array values.
Has Field
Thehas field
operator filters content which have the given JSON field.
Has Not Field
Thehas not field
operator filters content which do not have the given JSON field.
Boolean Operators
Operators above can be combined withAND
and OR
boolean operators to form
compound filters.
AND
will have higher
precedence than OR
. So, the filter
Filtering Nested Objects
It is possible to filter nested object fields by referencing them with the.
accessor.
Nested fields can be at arbitrary depths, so more than one .
accessor can be used
in the same identifier.
Filtering Array Elements
Apart from theCONTAINS
and NOT CONTAINS
operators, individual array elements can also
be filtered by referencing them with the []
accessor by their indexes.
Indexing is zero based.
#
character with negative values.
#
can be thought as the number of elements in the array, so [#-1]
would reference the
last element.
Miscellaneous
- Identifiers (the left side of the operators) should be of the form
[a-zA-Z_][a-zA-Z_0-9.[\]#-]*
. In simpler terms, they should start with characters from the English alphabet or_
, and can continue with same characters plus numbers and other accessors like.
,[0]
, or[#-1]
. - The string literals (strings in the right side of the operators) can be either single or double quoted.
- Boolean literals are represented as
1
or0
. - The operators, boolean operators, and boolean literals are case insensitive.