Update
Dynamic filters now support range operators (i.e., <, <=, >, >=). However, IS NULL
and grouping operators like parentheses are not supported. Therefore, the discontinue_on
field should be populated with a valid date or a date in the extreme future for products that cannot be discontinued. The filter statement would then look something like this.
INCLUDE ItemID WHERE Items.available_on <= $now AND Items.discountinue_on > $now AND Items.stock_on_hand > 0
Below is the relevant portion of the prior answer that is still applicable but may be less ideal than the solution above.
There are a couple alternative approaches that will also work. First, you can use a single field in your items dataset that indicates whether the item is available or not (e.g., is_available
). So a true
/false
value that represents the current state of 1/ being available, 2/ not discontinued, and 3/ with stock on hand. This means your application needs to update this flag for items when their availability status changes. In other words, when the item is discontinued or out of stock, change its is_available
field value to false
. This can be done using the PutItems API. Your filter becomes much simpler.
INCLUDE ItemID WHERE Items.is_available = "true"
Another approach would be to keep the available_on
, discontinue_on
, and stock_on_hand
in your items dataset and filter expression but replace $now
to a fixed/hard-coded value.
INCLUDE ItemID WHERE Items.available_on <= 20211105 AND Items.discontinue_on > 20211105 AND Items.stock_on_hand > 0
where 20211105
is the current date in YYYYMMDD
format. You can add hours, minutes, seconds for more granularity. Of course, this means that the datetimes in your filter expression need to be regularly updated. This requires periodically creating a new filter with updated datetimes, switching your app to use the new filter, and then deleting the old filter. Essentially rotating your filter over time. This serverless app can make this process much easier.
https://github.com/james-jory/amazon-personalize-filter-rotator