How to Configure Layered Navigation in Magento 2
Layered navigation (also called faceted navigation) allows customers to filter products by attributes such as price, color, size, or brand. Proper configuration of product attributes and search engine settings determines which filters appear and how they behave. Misconfigured attributes are a frequent cause of Elasticsearch errors and missing filters.
Attribute Configuration for Layered Navigation
For a product attribute to appear as a filter in layered navigation, it must be configured correctly in Stores → Attributes → Product.
Required Settings
Open the attribute and check the Storefront Properties tab:
- Use in Layered Navigation: Set to "Filterable (with results)" or "Filterable (no results)"
- "Filterable (with results)" shows the filter only when matching products exist
- "Filterable (no results)" always shows the filter, even when selecting it returns zero products
- Use in Search Results Layered Navigation: Set to "Yes" to show the filter on search results pages
Important Dependency
The option "Use in Search Results Layered Navigation" only appears in the admin when "Use in Search" is set to Yes. This behavior was introduced in Magento 2.4.5 and confuses administrators who expect to see all options regardless of other settings.
If you need the attribute filterable in search results but the option is not visible:
- Set "Use in Search" = Yes
- Save the attribute
- The "Use in Search Results Layered Navigation" option will now appear
- Set it to Yes and save again
Database Workaround for Older Migrations
If you upgraded from an older Magento version and the attribute's search filterable setting was not migrated correctly, you can set it directly in the database:
UPDATE catalog_eav_attribute
SET is_filterable_in_search = 1
WHERE attribute_id = (
SELECT attribute_id FROM eav_attribute
WHERE attribute_code = 'your_attribute_code'
AND entity_type_id = 4
);
After the database update, reindex:
php bin/magento indexer:reindex catalogsearch_fulltext
php bin/magento cache:flush
Attribute Types and Elasticsearch Compatibility
Not all attribute types work well with layered navigation. The attribute's frontend input type determines how Elasticsearch indexes and aggregates it.
Compatible Types
- Dropdown (select): Ideal for layered navigation. Creates clean filter options.
- Multiple Select: Works well, shows checkboxes for multi-value filtering.
- Price: Handled by Magento's built-in price navigation (range-based).
- Yes/No: Simple boolean filter.
Problematic Types
Text Field: Using a text-type attribute in layered navigation causes
illegal_argument_exception: Fielddata is disabled on text fields by defaultin Elasticsearch. Text fields are analyzed (tokenized) and cannot be used for aggregations without enabling fielddata, which is memory-intensive and not recommended.Solution: Do not use text-type attributes for layered navigation. Convert the attribute to a dropdown type, or set "Use in Layered Navigation" = No.
Text Area: Same issue as text fields.
See also: How to Configure Elasticsearch and OpenSearch in Magento 2
AJAX Filtering
AJAX-based layered navigation loads filtered results without a full page reload, providing a smoother user experience. For AJAX filtering to work correctly, the template markup must include the expected CSS class structure.
CSS Class Requirements
Magento's JavaScript (and third-party AJAX navigation extensions) identifies the product list and filter sidebar by specific CSS classes:
block-content-- wraps the filter options in the sidebarproducts-gridorproducts-list-- wraps the product listingtoolbar-- wraps the sorting/pagination toolbar
If you have customized templates (especially Hyva templates), verify these classes are present. AJAX navigation replaces content by targeting these class selectors. Missing classes cause the AJAX response to fail silently or replace incorrect page sections.
Reindexing After Configuration Changes
Any change to attribute filterable settings requires reindexing:
php bin/magento indexer:reindex catalogsearch_fulltext catalog_product_attribute
php bin/magento cache:flush
If filters still do not appear after reindexing, verify:
- The attribute is assigned to the attribute set used by products in the category
- Products in the category actually have values set for the attribute
- The category's "Is Anchor" setting is "Yes" (required for layered navigation to display)