Prompt
MongoDB Atlas Search is not giving us the relevance we need
Latest observation
If Atlas Search isn’t ranking results the way you expect, the fix usually comes down to index design, query construction, and relevance tuning rather than “search is bad.” Here’s a practical way to improve it.
1) Make sure the right fields are being searched
Common issue: all text is being thrown into one analyzed field, which weakens ranking.
Better approach:
- Search title, subtitle, tags, description separately
- Give important fields more weight
- Don’t rely on one giant catch-all field if relevance matters
Example with weighted fields:
{
$search: {
text: {
query: "wireless headphones",
path: [
{ value: "title", score: { boost: { value: 5 } } },
{ value: "tags", score: { boost: { value: 3 } } },
{ value: "description", score: { boost: { value: 1 } } }
]
}
}
}
2) Check your analyzer
If stemming, stop words, punctuation handling, or tokenization are off, relevance can get weird.
Questions to ask:
- Are you using the default analyzer when you need a language-specific one?
- Are synonyms being over-applied?
- Are you matching partial terms too aggressively?
- Is autocomplete being used where full-text search would be better?
For example:
- Use autocomplete only for typeahead
- Use text search for actual ranking
- Use phrase searches when word order matters
3) Use compound queries instead of a single text clause
Atlas Search often works better when you combine signals:
- Must match the main term
- Should match popular fields
- Filter by category, status, locale, etc.
Example:
{
$search: {
compound: {
must: [
{ text: { query: "wireless headphones", path: "title" } }
],
should: [
{ text: { query: "wireless headphones", path: "tags" } },
{ text: { query: "wireless headphones", path: "description" } }
],
filter: [
{ equals: { path: "isActive", value: true } }
],
score: {
boost: { value: 2 }
}
}
}
}
4) Tune scoring explicitly
If the default score isn’t enough:
- Boost exact matches
- Boost matches in titles more than body text
- Penalize stale or low-quality documents
- Use
functionscoring if you need business-specific ranking
For example:
- Newer content ranks higher
- Higher-rated products rank higher
- Items with more inventory rank higher
5) Watch out for autocomplete misuse
If you’re using autocomplete everywhere, you can get noisy results. Autocomplete is great for suggestions, but not always for final ranking.
Typical pattern:
- Typeahead:
autocomplete - Search results page:
text+compound - Exact title match: boosted
phrase
6) Add phrase and exact-match boosts
A document containing the exact search phrase should usually outrank loose matches.
Example:
{
$search: {
compound: {
should: [
{
phrase: {
query: "wireless headphones",
path: "title",
score: { boost: { value: 10 } }
}
},
{
text: {
query: "wireless headphones",
path: "description"
}
}
]
}
}
}
7) Validate with real queries
Relevance tuning only works with real examples. Create a small test set:
- 20–50 common queries
- Expected top 5 results for each
- Compare current vs improved ranking
This helps identify whether the problem is:
- Indexing
- Analyzer
- Query formulation
- Field weighting
- Missing business signals
8) Use scoreDetails to see why results rank as they do
Atlas Search can help you inspect scoring so you can see what’s driving rank.
If you’re unsure, this is often the fastest way to debug relevance:
- Which clause matched?
- Which field contributed most?
- Is a low-value field overpowering a high-value one?
A good default pattern
For many applications, this is a strong starting point:
- Index the relevant fields separately
- Use
compound - Boost title > tags > body
- Add exact phrase boosts
- Filter out irrelevant documents
- Tune analyzer and synonyms carefully
If you want, I can help you debug it directly
If you paste:
- your Atlas Search index definition, and
- one example query with “bad” results,
I can suggest a concrete scoring/query rewrite.
Brands