Skip to main content

Filter Expressions

Filter expressions are used when doing lookups in JSON or JavaScript schemas.

Below is a list of examples of what you can do with the filter.

tip

If you are using JavaScript and your filter contains expressions, it's often easier to use string interpolation instead of string concatination. See MDN Web Docs .

Examples

Examples of supported binary operators & expressions:

EQUALS operator
// Property value equal to constant string value
originId eq '100'

// Property value equal to expressed string value
originId eq '${sourceEntity.properties.selectedOtherPageId}'

// Property value is null
originParentId eq null

// Property value equal to integer value
properties.price eq 9

// Property value equal to decimal value
properties.price eq 9.99

// Property value equal to boolean value (true/false)
properties.isFeatured eq true
NOT EQUALS operator
// Property value not equal to constant string value
originId ne '100'

// Property value not equal to expressed string value
originId ne '${sourceEntity.properties.selectedOtherPageId}'

// Property value is not null
originParentId ne null

// Property value not equal to integer value
properties.price ne 9

// Property value not equal to decimal value
properties.price ne 9.99

// Property value not equal to boolean value (true/false)
properties.isFeatured ne true
AND operator
type eq 'article' and properties.isFeatured eq true
OR operator
type eq 'article' or type eq 'contentPage'
An array contains any matching value:
// Contains specific redirect with constant string value
redirects/any(r: r eq '/old-page')

// Contains specific tags with expression string value
properties.tags/any(t: t eq '${sourceEntity.properties.selectedTag}')

// Contains articles that feature, matching constant boolean value
properties.articles/any(a: a.isFeatured eq true)
info

Please note that our filter expressions only support one use of any per expression.
E.g. properties.tags/any(t: t eq 'tag1') or properties.tags/any(t: t eq 'tag2') is not supported.

Check whether the element exists in this collection
// Finds matches in predefined integers array
properties.favoriteId in (100, 200)

// Finds matches in predefined strings array
properties.color in ('blue', 'red', 'green')

// Finds matches in favorites selection (array of integers)
properties.favoriteId in (${sourceEntity.properties.favoriteIds})

// Finds matches in colors selection (array of strings)
properties.color in (${sourceEntity.properties.colors.map(c => `'${c}'`)})
Full example
export default {
// ...
properties: function (sourceEntity, context) {
return {
// ...
sportArticles: context
.reference('featuredSportArticle')
.filter(`type eq 'article' and properties.tags/any(t: t eq '${sourceEntity.properties.tag}')`)
.orderBy({ propertyName: 'properties.metaData.sortOrder', direction: "asc"})
.limit(5)
}
},
};