Improve Accuracy
How do I improve the accuracy of my search results?
To improve the accuracy of your search results, you can use Atlas Search support for the following features.
Customize the Score
Atlas Search assigns a score to every document in the result set based on relevance and returns the results in order from highest to the lowest score. To learn more, see Score the Documents in the Results.
When you run your Atlas Search query, you can tune the relevance of the documents in the results to ensure that the most pertinent documents are ranked and returned higher in the results.
To learn more, see How to Customize the Score of the Documents in the Results.
Hybrid Search
Hybrid search combines full-text search and semantic search to ensure synonymous and contextually similar matches are included in the combined results of both search methods for the same criteria in the same query.
Use hybrid search for the following scenarios:
Use Atlas Search (full-text search) to handle keyword queries and ranking documents based on relevance by measuring how frequently a keyword appears in a document and across the documents in the collection.
Use Atlas Vector Search (semantic search) to retrieve semantically similar documents.
Combine the scores of both search methods to retrieve more accurate and relevant results.
To learn more, see How to Perform Hybrid Search.
Synonyms Search
Synonyms search ensures that your query results contain relevant results even when the exact keywords aren't present in the documents that you search.
When you perform a synonyms search, you use the synonyms mapping collection that you indexed and apply at query-time.
To learn more, see Define Synonym Mappings in Your Atlas Search Index.
Explain Your Search
MongoDB explain
provides information about how queries execute and
why certain documents return over others.
Use explain
in your query for the following reasons:
Understand how Atlas Search computes scores for your search queries and the factors that contribute to the relevance of the documents in the results.
Improve your index and query based on the performance of your search and ranking.
To learn more, see How to Retrieve Query Plan and Execution Statistics.
How can I improve the relevancy of my search results?
You can tune the relevance in Atlas Search to ensure that the more pertinent documents return in your Atlas Search query results. Consider the following to optimize the relevance of your Atlas Search results.
Assess Your Data
To structure and format your data to return optimal results for your search:
Review the schema of your documents to determine which fields to index. For polymorphic data, Atlas Search indexes only documents that correspond to the mappings specified in the index definition for that field and ignores documents that contain values that aren't the data type specified in the index definition for that field. To learn more about supported field types and field mappings, see Define Field Mappings.
Normalize the data, if needed, to ensure consistency for fields used in filtering and sorting. For example, convert date and time values to a standard format, such as ISO-8601.
Analyze the frequency of common terms in key fields to determine the analyzer and tokenization strategy to apply. For example, some terms might require special handling like stemming or synonym mapping. To learn more about creating tokens for your data with Atlas Search analyzers, see Process Data with Analyzers.
Analyze the volume of data and plan for scale. Large datasets might require strategic indexing and partitioning.
Configure Your Atlas Search Index
To configure your Atlas Search index to return optimal results for your search:
Select the appropriate analyzer for each field that you want to index. Analyzers combine filters with tokenizers to create indexable terms that correct for differences in punctuation, capitalization, filler words, and more. You can choose built-in analyzers or build custom analyzers. To learn more, see Process Data with Analyzers.
Create a source synonym collection and define synonym mappings that reference the synonym source collection in your Atlas Search index. You can use synonyms to expand the scope of your search and to return related terms in the results. To learn more, see Define Synonym Mappings in Your Atlas Search Index.
Define Your Atlas Search Query
To build your query to return optimal results:
Select the appropriate aggregation pipeline stage. For example, use
$searchMeta
if you want to only retrieve metadata. To learn more, see Pipeline Stages.Choose an operator that is optimal for retrieving the relevant results. For example, consider compound if you want to combine multiple clauses such as
must
,should
,mustnot
in you query. To learn more, see Operators and Collectors.Apply more processes on your search results by using Atlas Search support for sorting, scoring, grouping, and more.
Prerequisites
To complete the tutorials, you must have:
An Atlas cluster with MongoDB version 4.2 or higher.
The sample data loaded into your Atlas cluster.
Project Data Access Admin
or higher access to your Atlas project to create Atlas Search indexes.Search Tester,
mongosh
, Compass, or a supported MongoDB Driver to run queries on your cluster.
Note
You can run Atlas Search queries by using any driver
through the $search
aggregation stage.
These tutorials include examples for a selection
of clients. Refer to the specific tutorial page for details.
You can also complete these tutorials with local Atlas deployments that you create with the Atlas CLI. To learn more, see Create a Local Atlas Deployment.