Lesson 5 of 9 · 28m
Relevance Tuning Without Cargo-Cult Boosts
Diagnose recall versus precision, use explain output, control matching with operators and boosts, and validate changes with real query sets.
Relevance tuning is where search teams accidentally become numerologists. Someone adds ^5 to a field, the demo query improves, and six months later nobody knows why part numbers outrank exact titles. Good relevance work starts with a judgment set: real queries, expected documents, and a definition of failure. Without that, every boost is superstition.
Separate recall from precision
Recall asks whether the right documents are in the candidate set. Precision asks whether the best documents rank near the top. A zero-result query can suffer from analysis failure, overly strict operators, missing synonyms, incorrect fields, or filters. A noisy result set may have plenty of recall but poor ranking. The remedies differ.
Use _validate/query?explain=true or the Explain API when a specific document should or should not match:
curl -s 'http://localhost:9200/products/_explain/abc123?pretty' -H 'content-type: application/json' -d '{
"query": {"match": {"title": "waterproof hiking boot"}}
}'The explanation tells you which clauses matched and how scoring contributions were calculated. Read it before touching boosts.
Build a defensible baseline query
A practical product or document search often combines fields with different jobs:
{
"query": {
"bool": {
"must": [{
"multi_match": {
"query": "waterproof hiking boot",
"type": "best_fields",
"operator": "and",
"fields": ["title^4", "brand^2", "description", "sku.exact^8"]
}
}],
"filter": [{"term": {"status": "published"}}],
"should": [
{"term": {"availability": {"value": "in_stock", "boost": 1.5}}}
]
}
}
}operator: and often improves precision because all analyzed terms must match. It can harm recall when users type noisy natural language. The answer is not ideology; measure both.
Synonyms, typo tolerance, and phrase behavior are product decisions
A synonym file can connect domain vocabulary:
boot, boots, footwear
laptop, notebook
tyre, tireBut synonyms can destroy precision if they expand unrelated meanings. Typo tolerance helps users and hurts exact technical search if applied blindly. Phrase queries reward ordered proximity, while match_phrase with slop can model near-exact text. Choose behavior per user journey: a support knowledge base, ecommerce catalog, log search, and legal document search do not share one relevance ideal.
Measure with real query sets
Create a small spreadsheet or automated harness:
query expected top docs failure mode
waterproof hiking boot boot-8831 first recall
c++ programming docs analysis
timeout api gateway incident runbook ranking
2026-01 invoice finance records mapping/filterTrack precision at rank 5 or 10, zero-result rate, and worst regressions. Reindex when analysis changes require it. Otherwise you are comparing old tokens against new expectations.
Field notes
- Beware
copy_tocatch-all fields: they increase index size and can mix unlike vocabularies into one noisy term space. - Function score and decay can encode freshness or popularity, but they can also bury exact matches if left unbounded.
- Explain output is verbose because scoring is detailed; do not tune from the final number alone.
- A/B test relevance changes when possible. Search quality is behavioral, not just mathematical.
Was this lesson helpful?