- 20 May 2024
- 2 Minutes to read
- Print
- PDF
Filters in Wasabi AiR
- Updated on 20 May 2024
- 2 Minutes to read
- Print
- PDF
Filters enable you to reduce the number of search results by defining matching criteria on the items. For example, you can find all items in which the last_modified field is between a specific date range.
You can filter full-text search results by adding a filters object to the search request object.
POST /api/data/search
{
"query": "{query}",
"limit": {limit},
"page": {page},
"filters": {
"terms": [{terms}],
"multi_terms": [{multi_terms}],
"ranges": [{ranges}],
"exists": [{exists}],
"not_exists": [{exists}]
}
}
- The filters object must have at least one property, which is one of the types of filters that may be applied.
- Although filters work without a query value, they are more expensive.
There are four types of filters:
- terms - Find objects in which fields match specified terms.
- multi_terms - Find objects in which fields match one of many specified terms.
- ranges - Find objects in which fields fit within a specified range.
- exists - Find objects that have a value for the specified fields.
- not_exists - Find objects that do not have a value for the specified fields.
terms Filters
The filters.terms array enables you to specify a list of terms to match. For example, to find all objects that have a specified md5, you would make the following request:
POST /api/data/search
{
"query": "{query}",
"filters": {
"terms": [
{"field":"md5", "value":"2ece57080d9545702d51cf1394b94142"}
]
}
}
- field - (string) The field to which you want to apply the filter.
- value - (string) The value to match.
multi_terms Filters
The filters.multi_terms array enables you to specify many values that objects must match. For example, to find all objects that have an extension of png or jpg, you would make the following request:
POST /api/data/search
{
"query": "{query}",
"filters": {
"multi_terms": [
{"field":"ext", "value":"png,jpg"}
]
}
}
- field - (string) The field to which you want to apply the filter.
- value - (string) A comma-separated list of values to match.
ranges Filters
The filters.ranges array enables you to specify a range of values for a given field. For example, to find all items that were last modified between two dates, you would make the following request:
POST /api/data/search
{
"query": "{query}",
"filters": {
"ranges": [
{ "field": "last_modified", "from": "2016-05-24", "to": "now"}
]
}
}
- field - (string) The field to which you want to apply the filter.
- from - (string) The lower bound of the range to match.
- to - (string) The upper bound of the range to match.
now is a special value that indicates the current date and time.
exists Filters
The filters.exists array enables you to specify fields that must appear in the matching items. Items that do not have a value for the specified field do not appear in the results. For example, to match all items that have exiv2 metadata, you would make the following request:
POST /api/data/search
{
"query": "{query}",
"filters": {
"exists": ["exiv2"]
}
}
- exists - (array of string) A list of fields that must exist for an item to appear in the search results.