Filtering Examples

Filtering Examples

This page provides a collection of real-world examples to demonstrate how to build complex queries using the API's advanced filtering capabilities. For a full list of operators, see the Advanced Filtering page.

E-Commerce Store

Goal: Find all products that are either on clearance or part of the "Summer Sale" collection, are currently in stock, and have a price lower than $50.

Collections:

  • products: with fields name, price (number), in_stock (boolean), tags (array).
  • promotions: with a field name (e.g., "Summer Sale").
  • A relation field campaign on products pointing to promotions.

Query:

/products?where[in_stock]=true&where[price][lt]=50&where[or][0][tags]=clearance&where[or][1][campaign][name]=Summer Sale

Explanation:

  • where[in_stock]=true: Filters for products that are in stock.
  • where[price][lt]=50: Filters for products that cost less than $50.
  • where[or][0][tags]=clearance: Begins an OR group, finding products tagged with "clearance".
  • where[or][1][campaign][name]=Summer Sale: The second part of the OR group, finding products related to a promotion named "Summer Sale".

Blog or News Site

Goal: Find all "published" articles by a specific author that were published after the start of 2023 and contain either "API" or "Headless" in their title.

Collections:

  • articles: with fields title, published_at (datetime), status (text).
  • authors: with a field name.
  • A relation field author on articles pointing to authors.

Query:

/articles?where[status]=published&where[author][name]=Jane Doe&where[published_at][gte]=2023-01-01T00:00:00Z&where[or][0][title][like]=API&where[or][1][title][like]=Headless

Explanation:

  • where[status]=published: Ensures only published articles are returned (core field filter).
  • where[author][name]=Jane Doe: A relational filter to get articles by a specific author.
  • where[published_at][gte]=...: Filters by a core datetime field.
  • where[or][...]: An OR group to find articles with "API" or "Headless" in the title.

Real Estate Listings

Goal: Find 2-bedroom apartments in "New York" that allow pets and whose price is not exactly $450,000.

Collections:

  • listings: with fields city, bedrooms (number), allows_pets (boolean), price (number).

Query:

/listings?where[city]=New York&where[bedrooms]=2&where[allows_pets]=true&where[price][not]=450000

Explanation:

  • This query chains multiple AND conditions.
  • where[price][not]=450000: Uses the not operator to exclude listings with a specific price.

Job Board

Goal: Find all remote "Software Engineer" or "Product Manager" jobs posted by the company "ElmapiCMS".

Collections:

  • jobs: with fields title, location_type (text), company_name (text).

Query:

/jobs?where[location_type]=remote&where[company_name]=ElmapiCMS&where[title][in]=Software Engineer,Product Manager

Explanation:

  • where[company_name]=ElmapiCMS: A simple equality filter.
  • where[title][in]=...: Uses the in operator to find jobs where the title is one of several options.

Search documentation

Find guides and reference pages