Skip to content

Filters

When searching from a PLP, filters are a vital part to enable users to narrow down what they are looking for. For filters to take effect, they must first be added as allowed filters. Ecommerce Search has two different filter types: term filters and range filters.

Term filter

A term filter takes a key and a list of terms, and a match value to determine how the filter should operate. Currently, allowed match types are: Any requiring any of the filter values to be present on a product, All requiring all of the filter values to be present on a product, and None requiring none of the filter values to be present on the product.

If the match type is not specified in a search request with a term filter, Any will be used by default.

Filter for either blue or white
1
2
3
4
5
6
7
8
{
    "filters": {
        "color": {
            "values": [ "blue", "white" ],
            "match": "any"
        }
    }
}
Filter for both waterproof and wind-resistant
1
2
3
4
5
6
7
8
{
    "filters": {
        "weather": {
            "values": [ "waterproof", "wind-resistant" ],
            "match": "all"
        }
    }
}

Range filter

A range filter takes a key and specifies a from and a to, it then filters products within this range. Either from or to can be left out, to filter unbounded.

Only one match type, Within, currently exists for range filters, including everything within the specified range. If the match type is not specified in a search request with a range filter, Within will be used by default.

Filter based on an attribute being within a certain range
1
2
3
4
5
6
7
8
{
    "filters": {
        "size": {
            "from": 41,
            "to": 43
        }
    }
}

Missing Fields

Missing field behavior specifies how the search API handles documents that are missing certain fields when performing searches. This is beneficial when using Unified Search, which returns both products and content which do not share all fields. For example, content does not have a stock or price field, but products do.

When defining a filter you can populate the missing field behavior field. The default behavior is ignoring the document.

Option Behavior
MatchDocument Documents with missing fields will be included regardless of filter value.
IgnoreDocument Documents with missing fields will be filtered away.

Using MissingFieldBehavior on domain filter

When searching with a domain filter on price, with MissingFieldBehavior set to MatchDocument, ECS will return both content and products. With MissingFieldBehavior set to IgnoreDocument only the products will be returned as the content doesn't have the price field.

Facets

Facets are filters which allow users to narrow down search results based on specific attributes on products, SKUs or content. These attributes can be anything from color, price, brand, size, etc.

Facets must be created on a context before they can be used. Creating facets has several steps:

  1. Ingest products with attributes
  2. Add the field you want to use for the facet as an allowed filter
  3. Add the field as a context facet on a given context
  4. Do a search that resolves to that context

Given a context with Color and Price as Context facets and the following search request:

Search request
1
2
3
4
5
{
  "segmentId": "b2c-dk-da",
  "scopeId": "Browse",
  "phrase": ""
}

Ecommerce Search returns the following facets.

Facet than can be applied
{
    "facets": [
        {
            "key": "COLOR_ATTRIBUTE_ID",
            "name": "Color",
            "facetType": "Term",
            "max": null,
            "min": null,
            "selectedTo": null,
            "selectedFrom": null,
            "values": [
            {
                "count": 4,
                "isSelected": false,
                "key": "BLUE_ID",
                "name": "Blue",
            },
            {
                "count": 4,
                "isSelected": false,
                "key": "GREY_ID",
                "name": "Grey",
            },
            {
                "count": 4,
                "isSelected": false,
                "key": "ORANGE_ID",
                "name": "Orange",
            }
            ]
        },
        {
            "key": "Price",
            "facetType": "Range",
            "max": 1300,
            "min": 500,
            "selectedTo": null,
            "selectedFrom": null,
            "values": null
        }
    ]
}

It shows two facets; color and price. Each facet contains a key, which represents the attribute name, a facetType which specifies the type, either a Term or a Range. There is also the name, that is the display name of the facet.

The values, min, and max are values denoting the possible values in the dataset. In this case, it means that if a color filter is applied, the minimum and maximum price will change to the actual minimum and maximum price of the products with that color.

Term facets contain a list of values, listing all possible values for the given key. It also specifies if the facets are selected or not, and which specific values from the facet that has been selected.

Range facets contain min and max which specifies the range of values of the products. It also shows the selected from and to.

Note

When resolving context facets, both the filter key, e.g. Color, and the match type, default Any for term filters and Within for range filters, must match. If a filter in a search request does not match any context facets, it will not function as a facet, but as a domain filter.

Example

Request
{
    "segmentId": "b2c-dk-da",
    "scopeId": "Browse",
    "phrase": "",
    "filters": {
        "Color": {
            "values": [ "BLUE_ID" ]
        },
        "Price": {
            "from": 600,
            "to": 900
        }
    }
}
Response
{
    "facets": [
        {
            "key": "COLOR_ATTRIBUTE_ID",
            "name": "Color",
            "facetType": "Term",
            "max": null,
            "min": null,
            "selectedTo": null,
            "selectedFrom": null,
            "values": [
                {
                "count": 4,
                "isSelected": true,
                "key": "BLUE_ID",
                "name": "Blue",
                },
                {
                "count": 4,
                "isSelected": false,
                "key": "GREY_ID",
                "name": "Grey",
                },
                {
                "count": 4,
                "isSelected": false,
                "key": "ORANGE_ID",
                "name": "Orange",
                }
            ]
        },
        {
            "key": "Price",
            "facetType": "Range",
            "max": 1000,
            "min": 500,
            "selectedTo": 900,
            "selectedFrom": 600,
            "values": null
        }
    ]
}

Facets & Missing Field Behavior

Documents with missing fields are not counted towards facets.

Domain filters

A domain filter can be applied even if it is not a facet. This will ensure a more accurate and specific calculation of facets. Content and products that are excluded by a domain filter will not be included in the calculation of Total hits, and will not be used in the calculation of facets.

Domain filters are not intended for end-users to apply themselves, but instead are determined by their scope and credentials.

Domain filters cover the following filter types:

Using domain filters

A commonly used domain filter could be CategoryIds, which might be pre-applied when searching from certain pages on your ecommerce site.

Filters can be represented by the following diagram:

Filtering

Filtering on predefined fields

Ecommerce Search has some predefined fields on content and products/SKUs. The following table provides an overview of filterable predefined fields. Note that not all of these have filtering enabled by default, see Allowed Filters for additional information. It is also important to note that the field names are case sensitive.

Field Type Default Filterable
CategoryNames Term
CategoryIds Term
Price Range
SearchableIds Term
InStock Term
Inactive Term

Filtering on predefined fields

Filterering on the predefined field CategoryNames

1
2
3
4
5
6
7
8
{
    "filters": {
    "CategoryNames": {
        "values": [ "Makeup" ],
        "match": "all"
        }
    }
}