Skip to content

Handling Redirects

When redirects are enabled, the Unified Search response may include an action object instructing the frontend to navigate the user to a specific page instead of displaying search results.

Detecting a redirect

Check for the presence of action.redirect in the search response. When present, the filters dictionary contains the field name and target identifier for the redirect.

Response with redirect

{
    "action": {
        "redirect": {
            "filters": {
                "CategoryIds": "42"
            }
        }
    },
    "originalPhrase": "running shoes",
    "usedPhrase": "running shoes",
    "products": [],
    "totalProducts": 0
}

Filter keys

The filters dictionary maps field names to target identifiers. The key tells you the type of redirect:

Filter key Redirect type Target page
CategoryIds Category Product listing page (PLP) filtered by category
ProductId Product name Product detail page (PDP)
SkuId SKU ID Product detail page (PDP)
SkuNo SKU number Product detail page (PDP)
(custom attribute fieldId) Custom attribute PLP filtered by the attribute value

Implementation

The general pattern for handling redirects is:

  1. Perform the search request
  2. Check if action.redirect exists in the response
  3. If present, map the filter to a URL in your application and navigate
Vanilla JavaScript
async function handleSearch(phrase) {
    const response = await fetch('/api/search', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
            segmentId: 'b2c-dk-en',
            scopeId: 'full-search',
            phrase: phrase
        })
    });

    const result = await response.json();

    // Check for redirect action
    if (result.action?.redirect) {
        const url = mapFiltersToUrl(result.action.redirect.filters);
        window.location.href = url;
        return;
    }

    // No redirect — display search results normally
    displayResults(result);
}

function mapFiltersToUrl(filters) {
    if (filters.CategoryIds) {
        return `/category/${filters.CategoryIds}`;
    }
    if (filters.ProductId || filters.SkuId || filters.SkuNo) {
        const productId = filters.ProductId || filters.SkuId || filters.SkuNo;
        return `/product/${productId}`;
    }
    // Custom attribute — build a filtered PLP URL
    const [attribute, value] = Object.entries(filters)[0];
    return `/products?${attribute}=${encodeURIComponent(value)}`;
}

Note

The mapFiltersToUrl function is specific to your frontend's URL structure. Adapt the URL patterns to match your application's routing.

Redirect behavior differs depending on the search type:

Search type Redirect behavior
Full search Returns only the action object — no products, content, or other results. The frontend should navigate immediately.
Quick search Returns the action object and limited results. Products are fetched using the redirect filters, so they match the redirect target.

For full search, always check for redirects before rendering results. For quick search, you can show a preview of matching products while offering a link to the redirect target.

Quick search with redirect

When quick search detects a redirect, it follows the redirect internally and returns matching products:

Quick search response
{
    "action": {
        "redirect": {
            "filters": {
                "CategoryIds": "42"
            }
        }
    },
    "products": [
        { "id": "prod-1", "name": "Trail Runner Pro" },
        { "id": "prod-2", "name": "Road Runner Lite" }
    ],
    "totalProducts": 87,
    "originalPhrase": "running shoes",
    "usedPhrase": "running shoes"
}

When redirects do not trigger

Redirects are skipped when:

  • No search phrase is provided
  • The user has applied filters or facets (not a pristine search)
  • The search phrase does not match any configured redirect source
  • The matched entity is ambiguous (e.g., a category name exists in multiple category paths)
  • No products exist for the matched entity
  • For PDP redirects: more than one unique product matches

Admin API reference

Redirect settings are managed per segment and go through the publication flow.

Get current settings

GET /segment/{segmentId}/redirect-settings
Response
{
    "categoryEnabled": true,
    "productNameEnabled": false,
    "skuIdEnabled": true,
    "skuNoEnabled": false,
    "customAttributes": [
        {
            "fieldName": "brand",
            "displayName": "Brand"
        }
    ]
}

Update settings

POST /segment/{segmentId}/redirect-settings
Request body
1
2
3
4
5
6
7
{
    "categoryEnabled": true,
    "productNameEnabled": true,
    "skuIdEnabled": true,
    "skuNoEnabled": false,
    "customAttributes": ["brand"]
}

Response: 204 No Content

Note

After updating redirect settings, you must publish the segment for changes to take effect in live search.

Get available custom attributes

GET /segment/{segmentId}/redirect-settings/available-attributes

Returns all string-type product attributes that can be used for redirect configuration:

Response
[
    {
        "fieldName": "brand",
        "displayName": "Brand"
    },
    {
        "fieldName": "material",
        "displayName": "Material"
    }
]

Error responses

Status Condition
400 Bad Request Duplicate custom attributes in request, or custom attributes not found in product fields
404 Not Found Segment does not exist
429 Too Many Requests Rate limit exceeded

Migration from external redirects

If you currently handle redirects outside of Ecommerce Search (e.g., in a middleware or frontend layer):

  1. Enable redirect settings for the relevant segment via the Admin API
  2. Publish the segment to activate the settings
  3. Verify using the Playground in the admin UI to test specific search phrases
  4. Update your search handler to check for action.redirect in responses
  5. Remove external redirect logic once ECS-native redirects are confirmed working

Troubleshooting

Issue Cause Solution
Redirect not triggering Settings not published Publish the segment after changing redirect settings
Redirect not triggering Search has filters applied Redirects only fire on pristine searches (no user-applied filters)
Wrong category redirect Ambiguous category name Ensure category names are unique across category paths
No PDP redirect Multiple products match PDP redirects require exactly one unique product match
Redirect for wrong attribute Attribute not configured Verify the custom attribute is listed in redirect settings