search mobile facets autocomplete spellcheck crawler rankings weights synonyms analytics engage api customize documentation install setup technology content domains user history info home business cart chart contact email activate analyticsalt analytics autocomplete cart contact content crawling custom documentation domains email engage faceted history info install mobile person querybuilder search setup spellcheck synonyms weights engage_search_term engage_related_content engage_next_results engage_personalized_results engage_recent_results success add arrow-down arrow-left arrow-right arrow-up caret-down caret-left caret-right caret-up check close content conversions-small conversions details edit grid help small-info error live magento minus move photo pin plus preview refresh search settings small-home stat subtract text trash unpin wordpress x alert case_deflection advanced-permissions keyword-detection predictive-ai sso

Filters

Engine Type Supported?
Crawler-based Engine YES
API-based Engine YES

Filters apply conditions to matching document fields to reduce a result set.

q
required
The query used within your search.
engine_key
required
The Engine Key associated with your Engine. Found within your dashboard.
filters
optional
Provide the filters parameter with a DocumentType key, and then provide that key with fields from your schema. To filter, provide the fields with a value to filter upon.

Basic Filtering

Filter by matching on a specific value.

Example - Return books matching the query "brothers" in the books DocumentType that are "in_stock":"true" and "genre":"fiction" only. Crawler based Engines use page as the default DocumentType.
curl -XGET 'https://search-api.swiftype.com/api/v1/public/engines/search.json' \
  -H 'Content-Type: application/json' \
  -d '{
        "engine_key": "YOUR_ENGINE_KEY",
        "q": "brothers",
        "filters":{
          "books":{
            "genre":"fiction",
            "in_stock":"true"
          }
        }
      }'

Multiple Value Filters

Filters can also have multiple values.

Example - Return books matching the query "brothers" that are in the mystery OR science fiction genres.
curl -XGET 'https://search-api.swiftype.com/api/v1/public/engines/search.json' \
  -H 'Content-Type: application/json' \
  -d '{
        "engine_key": "YOUR_ENGINE_KEY",
        "q": "brothers",
        "filters":{
          "books":{
            "genre": ["mystery", "science fiction"]
          }
        }
      }'

Filter Negation

You may want to filter out a particular field value.

For that, you can use the ! operator.

Example - Return all books, except those of the mystery genre.
curl -XGET 'https://search-api.swiftype.com/api/v1/public/engines/search.json' \
  -H 'Content-Type: application/json' \
  -d '{
        "engine_key": "YOUR_ENGINE_KEY",
        "q": "brothers",
        "filters":{
          "books":{
            "genre": ["!mystery"]
          }
        }
      }'

Filters with AND Semantics

By default, if you pass multiple values to a filter we apply OR semantics to the match.

To apply AND semantics, you may use the AND filter.

type
optional
The type of filter. Within the field being filtered, provide the type as and.
values
optional
Within the field being filtered, provide the values to and between.
Example - Return books matching the query brothers that are in both the mystery AND science fiction genres.
curl -XGET 'https://search-api.swiftype.com/api/v1/public/engines/search.json' \
  -H 'Content-Type: application/json' \
  -d '{
        "engine_key": "YOUR_ENGINE_KEY",
        "q": "brothers",
        "filters":{
          "books":{
            "genre":{
              "type": "and",
              "values": ["mystery","science fiction"]
            }
          }
        }
      }'

Geospatial Queries

Geospatial queries require latitude and longitude coordinates.

Units can be miles (mi) or kilometers (km).

type
optional
The type of filter. Within the field being filtered, provide the type as distance.
max
optional
Toggle the amount of distance from your specific coordinates wherein results are considered within proximity. Requires latitude and longitude.
lat
optional
The latitude of the location. Requires longitude.
lon
optional
The longitude of the location. Requires latitude.
Example - Return books matching the query "brothers" within 5km of the geographic location (37.75,-122.42).
curl -XGET 'https://search-api.swiftype.com/api/v1/public/engines/search.json' \
  -H 'Content-Type: application/json' \
  -d '{
        "engine_key": "YOUR_ENGINE_KEY",
        "q": "brothers",
        "filters":{
          "books":{
            "publisher_location":{
              "type": "distance",
              "max": "5km",
              "lat": 37.75,
              "lon": -122.42
            }
          }
        }
      }'

Range Queries

Filters also support range queries.

Apply range filters to date, integer, and float fields.

If you want the filter unbounded at the low or the high end, just leave off the from or the to parameter.

type
optional
The type of filter. Within the field being filtered, provide the type as range.
from
optional
The bottom end of the range, where the range begins.
to
optional
The top end of the range, where the range ends.
Example - Return books matching the query "brothers" with a price between 3.00 and 12.00.
curl -XGET 'https://search-api.swiftype.com/api/v1/public/engines/search.json' \
  -H 'Content-Type: application/json' \
  -d '{
        "engine_key": "YOUR_ENGINE_KEY",
        "q": "brothers",
        "filters":{
          "books":{
            "price":{
              "type": "range",
              "from": 3.00,
              "to": 12.00
            }
          }
        }
      }'

Supported Field Types

Type Filtering
string Yes
text No
enum Yes
integer Yes
float Yes
date Yes
location Yes

Stuck? Looking for help? Contact support or check out the Site Search community forum!