Web / Apache Solr Interview questions
How do you optimize faceted search performance on large collections?
Faceting cost grows with both the number of unique values in a field and the number of matching documents, so optimization usually targets one of those two dimensions.
- Enable docValues on faceted fields. Without it, Solr builds an in-memory uninverted index (fieldCache) on first use, which is slow to build and heavy on heap. DocValues moves this to an on-disk, memory-mapped columnar structure built at index time instead.
- Choose the right facet.method -
fc(field cache/docValues-based) generally wins for fields with many unique values, whileenumcan be faster for low-cardinality fields like a status flag. - Limit facet.limit and use facet.mincount=1 to avoid computing and transferring buckets nobody will use.
- Prefer the JSON Facet API for multi-level or nested facets - it can compute several aggregations in a single pass instead of Solr's older, separate facet parameters requiring multiple internal computations.
- Cache filter clauses shared with facets so the base document set doesn't get recomputed for every facet field.
On very large, high-cardinality fields (like a free-text tag field with millions of unique values), consider whether faceting is even the right tool - a dedicated aggregation or a pre-computed summary table sometimes serves the UI need better than live faceting.
More Related questions...