Data filters allow to filter out entities that match given conditions.
Example use of a condition in a filter
In the following example a condition is used in an entity filter to remove products that are not in the right set of categories.
{
"prototype": "data",
"parameters": {
"filters": [
{
"prototype": "value-condition",
"parameters": {
"accessor": {
"prototype": "key",
"parameters": {
"keys": [
"categories"
]
}
},
"conditions": [
{
"prototype": "list-contains",
"parameters": {
"value": "flora"
}
},
{
"prototype": "list-contains",
"parameters": {
"value": "flowers"
}
}
]
}
}
]
}
}
Input:
[
{
"sku": "tnt-1001",
"categories": ["explosive", "tnt"]
},
{
"sku": "ignition",
"categories": ["explosive", "peripherals"]
},
{
"sku": "rose",
"categories": ["flora", "flowers"]
},
{
"sku": "tulip",
"categories": ["flora", "flowers"]
},
{
"sku": "growth-stimulant",
"categories": ["flora"]
}
]
Output:
[
{
"sku": "rose",
"categories": [
"flora",
"flowers"
]
},
{
"sku": "tulip",
"categories": [
"flora",
"flowers"
]
}
]
Types of filters
The following are available by default.
To introduce custom filtering logic, !! a new data filter !! can be created.
Value condition
Code: value-condition
Applies one or more !! conditions !! on the values that are retrieved from an !! accessor !!.
Property | Type | Required | Description |
---|---|---|---|
accessor | object | Yes | The accessor to apply matching entities. |
keys | string[] | No | The keys to validate the conditions against. |
conditions | object[] | No | The conditions to apply. |
Input:
[
{
"sku": "tnt-1001",
"categories": ["explosive", "tnt"]
},
{
"sku": "ignition",
"categories": ["explosive", "peripherals"]
},
{
"sku": "rose",
"categories": ["flora", "flowers"]
},
{
"sku": "tulip",
"categories": ["flora", "flowers"]
},
{
"sku": "growth-stimulant",
"categories": ["flora"]
}
]
Filter:
{
"prototype": "value-condition",
"parameters": {
"accessor": {
"prototype": "key",
"parameters": {
"keys": [
"categories"
]
}
},
"conditions": [
{
"prototype": "list-contains",
"parameters": {
"value": "flora"
}
},
{
"prototype": "list-contains",
"parameters": {
"value": "flowers"
}
}
]
}
}
Output:
[
{
"sku": "rose",
"categories": [
"flora",
"flowers"
]
},
{
"sku": "tulip",
"categories": [
"flora",
"flowers"
]
}
]