Facet Management
Facet management lets you control which filters appear in search results, their configuration, and how they aggregate data to create optimal navigation experiences.
Overview
Facets (filters) help users refine search results by showing available options for attributes like brand, price, color, and category. Facet management gives you control over which facets appear, how they're configured, and how they aggregate data.
Facet Configuration
Facets are configured in the search API using the facets parameter. The configuration includes:
Global Facet Parameters
fields: Map of field names to their facet configurationmaxResults: Maximum number of facet results to return per field (default: 100, max: 10000)maxDepth: Maximum number of documents to consider for aggregation per shard (optional, improves performance)order: Order of facet results -asc(ascending) ordesc(descending) based on count (default:desc)
Field-Level Parameters
Each field in the fields map can have:
type: Facet type -string,number(for integer and float fields), orarraymaxResults: Overrides globalmaxResultsfor this specific fieldorder: Overrides globalorderfor this fieldranges: For numeric fields only - defines ranges for bucketing numeric valuesexcludeTerms: Excludes specific terms from the filter query for that facet field
Range Parameters (for numeric fields)
When using ranges for numeric fields, each range object can have:
from: Lower bound of the range (inclusive). If not specified, treated as-Infto: Upper bound of the range (exclusive). If not specified, treated asInfname: Custom name for the range (defaults to"from:to"format)
Facet Types
String Facets
String facets aggregate text values and return counts for each unique value:
{
"facets": {
"fields": {
"color": {"type": "string"}
}
}
}
Response:
{
"facets": {
"color": {
"red": {"count": 5},
"blue": {"count": 3},
"green": {"count": 2}
}
}
}
Numeric Facets
Numeric facets provide statistics (min, max, avg, sum, count) for numeric fields:
{
"facets": {
"fields": {
"price": {"type": "number"}
}
}
}
Response:
{
"facets": {
"price": {
"min": 1.2,
"max": 99.9,
"avg": 37.5,
"sum": 262.5,
"count": 7
}
}
}
Numeric Range Facets
Define custom ranges for numeric fields:
{
"facets": {
"fields": {
"price": {
"type": "number",
"ranges": [
{"to": 50, "name": "budget"},
{"from": 50, "to": 100},
{"from": 100, "name": "premium"}
]
}
}
}
}
Response:
{
"facets": {
"price": {
"budget": {
"min": 10.99, "max": 49.99, "avg": 29.99, "sum": 149.95, "count": 5
},
"50.0:100.0": {
"min": 59.99, "max": 99.99, "avg": 79.99, "sum": 319.96, "count": 4
},
"premium": {
"min": 129.99, "max": 199.99, "avg": 164.99, "sum": 494.97, "count": 3
}
}
}
}
Array Facets
Array facets aggregate values from array fields:
{
"facets": {
"fields": {
"tags": {"type": "array"}
}
}
}
Response:
{
"facets": {
"tags": {
"color": {"red": {"count": 5}, "blue": {"count": 3}},
"brand": {"Marqo": {"count": 4}, "FashionBrand": {"count": 2}},
"type": {"shirt": {"count": 8}}
}
}
}
Advanced Configuration
Excluding Terms
Exclude specific terms from facet results:
{
"facets": {
"fields": {
"color": {"type": "string", "excludeTerms": ["color:red"]},
"brand": {"type": "string", "maxResults": 10, "excludeTerms": ["brand:Marqo"]}
}
}
}
Custom Ordering
Set custom ordering per field:
{
"facets": {
"fields": {
"category": {"type": "string", "maxResults": 5, "order": "asc"}
},
"order": "desc"
}
}
Performance Optimization
Use maxDepth to limit documents considered for aggregation (improves performance):
{
"facets": {
"maxDepth": 1000,
"fields": {
"brand": {"type": "string"}
}
}
}
Best Practices
- Choose relevant fields: Select fields that users actually want to filter on
- Limit facet count: Use
maxResultsto avoid overwhelming users with too many options - Use ranges for prices: Create meaningful price ranges for better UX
- Optimize performance: Use
maxDepthfor large catalogs to improve response times - Exclude irrelevant terms: Use
excludeTermsto hide values that shouldn't appear - Order logically: Use
orderto show most popular or relevant options first
Related Topics
- Dynamic Facets - Context-aware facet display
- Search Analytics - Track facet usage