Web / Apache Lucene Interview questions
How do you troubleshoot slow queries in Lucene?
Slow-query investigation in Lucene usually follows a fairly consistent checklist rather than guesswork:
- Inspect the query shape - leading wildcards (
*term) and broad fuzzy queries are inherently expensive since they can't use the term dictionary efficiently. - Check field analysis - a mismatched or overly complex Analyzer can bloat the term dictionary and slow term lookups.
- Check segment count - too many small segments increases per-segment overhead; this usually points at MergePolicy or commit frequency issues.
- Warm the searcher - a freshly reopened IndexSearcher with cold caches (especially DocValues) will be slower on its first queries.
- Use IndexSearcher.explain() on a slow query to see exactly which clauses are contributing the most scoring work.
Most real-world slowdowns trace back to one of the first two items - an unbounded wildcard/fuzzy query, or an Analyzer producing far more distinct terms than the field actually needs.
More Related questions...