Define Filter Language
- Data
- Datastore
3 min read | Last updated :
The platform provides support for advanced filtering through Kisai’s own filtering language. The language is simple to use and provides flexibility to query data in complex scenarios like accessing jsonb fields, recursive jsonbs, references.
NOTE
Kisai filtering language is not turing complete.Filter Structure
Below is the basic structure for filtering
| Name | Description |
|---|---|
| Field Name | Fields of the entity |
| Operator | Operation to be performed |
| Filter Criteria | Filter to be applied |
Operators
Kisai provides support for the following operators.
NOTE
All operator keywords are case sensitive.Comparison Operators
| Operator | Description | Example |
|---|---|---|
| < | Less Than | price < 20 |
| > | Greater Than | quantity > 40 |
| = | Equal | quantity = 100 |
| <= | Less than equal | quantity <= 200 |
| >= | Greater than equal | quantity >= 200 |
| is | To check if value is null or boolean | id is false |
| is not | To check if value is not null or boolean | id is not null |
| not | To check if value is not null or boolean | id not true |
Pattern Matching
| Operator | Description | Example |
|---|---|---|
| like | Like | name like ‘sam%‘ |
| notlike | not like | name not like ‘A_b%‘ |
| ilike | Use ilike to match for case insensitive | name ilike ‘SAM%‘ |
| not ilike | Not like with case insensitive | name not ilike ‘%a_B_c%‘ |
| match | ||
| not match | ||
| imatch | ||
| not imatch |
Logical Operators
| Operator | Description | Example |
|---|---|---|
| and | Returns true only when all conditions are met | id = 200 and name = ‘Peter’ |
| or | Returns true when any one of the condition is met | id = 200 or name = ‘Peter’ |
IN Operator
| Operator | Description | Example |
|---|---|---|
| in | Returns true only when any of the value in the list is met | id IN (200,300,400) |
Index for Array Fields
Index operator can be used for fields which are array datatype.
| Operator | Description | Example |
|---|---|---|
| indexOf | Returns true when if the expression is met | serviceoptions.array[]=‘Takeaway’ |
NOTE
Jsonb fields can be accessed using dot notation like pastaddresses.array[].city = ‘Hyderabad’Example 1 - Filter by id
Let’s find out how the item with id = “01GE17TDS8DFPXF34ANP60JS53”
Request
1URI : /data/rest/:entity?filter=id="01GE17TDS8DFPXF34ANP60JS53"Response
1{2 "data": {3 "items": {4 ...5 "id": "01GE17TDS8DFPXF34ANP60JS53",6 ...7 "itemname": "Deluxe Veggie",8 ...9 }10 }11}Example 2 - Filter using like operator
Let’s find out items who have name like ‘%Veg%‘
Request
1URI : /data/rest/:entity?filter=itemname like '%25Veg%25'Response
1{2 "data": {3 "items": {4 ...5 "itemdesc": "Veg delight - onion, capsicum,grilled mushroom , corn & paneer",6 "itemname": "Deluxe Veggie",7 ...8 }9 }10}Example 3 - Filter using AND operator
Let’s find out all items which have veg (case insensitive) in their name and price is less than 600
Request
1URI : /data/rest/:entity?filter=itemname ilike '%25veg%25' and price < 600Response
1{2 "data": {3 "items": [4 {5 ...6 "itemdesc": "Veg delight - onion, capsicum,grilled mushroom , corn & paneer",7 "itemname": "Deluxe Veggie",8 ...9 },10 {11 ...12 "itemdesc": "The fresh garden combination of lettuce, cucumber,tomato, onion and cheese",13 "itemname": "The Special Veggie Club Sandwich",14 ...15 }16 ]17 }18}Example 4 - Filter using indexOf
Let’s find all the outlets which support Dine in
Request
1URI : /data/rest/:entity?filter=serviceoptions.array[] in ['Dine in']Response
1{2 "data": {3 "outlets": {4 ....5 "outletid": "01GE1DBGFC8D8545YM6YXFWK6C",6 "serviceoptions": [7 "Takeaway",8 "Dine in",9 "No Contact Delivery"10 ],11 ...12 }13 }14}