Overview

11 Carrying out full-text search using Atlas Search

Full-text search is critical for applications ranging from e-commerce and customer support to research and log analytics because it goes beyond exact-word matching to rank relevance, handle phrases, proximity, fuzziness, and wildcards. The chapter explains how Apache Lucene powers these capabilities through inverted indexes and relevance scoring, and it outlines the drawbacks of pairing a database with a separate search engine—namely integration complexity, synchronization risk, operational overhead, and cost. Atlas Search, built on Lucene and integrated directly into MongoDB Atlas, addresses these issues by providing a single query API, automatic synchronization via change streams, and unified management without maintaining a separate search stack.

Architecturally, Atlas Search runs a mongot process alongside mongod on each node (or on dedicated Search Nodes for workload isolation), keeping indexes eventually consistent with data changes. You define search indexes per collection using dynamic or, preferably, static mappings; configure analyzers (standard, simple, whitespace, language, keyword) or custom analyzers; and optionally add synonyms and storedSource. Reindexing occurs when index definitions change or certain system events require it, and it demands extra storage headroom. The chapter walks through creating an index via the Atlas CLI with static mappings, explains that Atlas Search stores Lucene indexes rather than duplicating documents, and clarifies that searches use the index to find matching IDs and then fetch the latest documents from the collection.

Querying is done with aggregation stages $search and $searchMeta (both must start the pipeline), combining Lucene-powered operators and MongoDB stages. Supported operators include text, phrase (with slop for proximity), wildcard, fuzzy, regex, range, near, equals, in, autocomplete, moreLikeThis, compound, embeddedDocument, and geo operators, plus collectors like facet for result grouping. The chapter demonstrates practical patterns: compound queries with relevance scores, typo tolerance with fuzzy, proximity searches with phrase, pattern matching with wildcard, faceting for drill-downs, and retrieving counts and diagnostics via $$SEARCH_META and $searchMeta. It also covers index management commands in mongosh, cluster tier considerations and limits, performance and storage tips (e.g., static mappings, reindex planning, disk overhead), and how to experiment safely in the Atlas Search Playground along with its constraints.

High-level data synchronization architecture. The application uses a database driver and query language to interact with the database cluster, and a search driver and query language to interact with the search cluster. Data synchronization occurs between the database cluster and the search cluster. This setup can lead to increased management complexity, potential synchronization issues, and higher resource consumption due to the need to maintain both the database and search clusters.
Atlas Search high level overview. An application using MongoDB Atlas, where the application interacts with both Atlas Database and Atlas Search through a unified driver and query API. Within the MongoDB Atlas environment, the application can seamlessly access both the database and search functionalities without needing separate integrations or synchronization processes. This unified approach simplifies the architecture by allowing the application to use the same API for both data storage and search operations.
The Atlas Search architecture integrates MongoDB with the Lucene Search Index managed by the mongot process. MongoDB (mongod) serves as the primary database, sending object IDs and metadata to mongot via change streams for synchronization and monitoring. Mongot uses APIs for index configuration and search operations. The Lucene component handles search indexes and ObjectIDs, enabling efficient query processing. Index configuration is managed through MongoDB Atlas Automation, interfacing with the Atlas UI, API, and CLI. Search queries initiated via mongosh, Compass, or drivers are processed by the Atlas Search cluster.
Within the Atlas Search Nodes Architecture, multiple MongoDB (mongod) instances manage data storage and execute search queries, forwarding them to mongot processes. These processes handle initial synchronization and continuous updates via change streams, ensuring search indexes are consistently updated with the latest data changes across all nodes.
Atlas Search Index. On the left side of the screen, there is a collapsible navigation menu. To access the Search Index view, the Search & Vector Search option under the DATA section must be clicked. Once selected, the main panel displays details of the search indexes. In this example, the sample_training database and its inspections collection are shown with an active search index named MongoDB-In-Action. The index is marked as READY and is fully queryable, indicated by the green checkmark.
The Atlas Search Playground, where users can configure and test search queries in MongoDB Atlas. It includes sections for writing queries, configuring the search index, viewing the data source, and displaying results. This interface allows users to experiment with search features and see how their queries perform on sample data before applying them in a live environment.
Atlas Search Playground Pre-Configured Environments.

Summary

  • Full-text search surpasses traditional methods by analyzing document content for relevance, phrases, citations, and attributes. It supports various types like simple keyword, Boolean, fuzzy, wildcard, phrase, proximity, range, and faceted searches. This versatility makes it ideal for applications ranging from quick queries to complex filtering tasks.
  • Using separate solutions for database management and full-text search introduces complexity in data synchronization and query handling. This setup requires extra maintenance and monitoring, leading to potential consistency issues, increased costs, and additional operational overhead for DevOps teams.
  • Apache Lucene is a high-performance Java library that offers advanced search features including indexing, spellchecking, and text analysis. It's part of an open-source project that also includes PyLucene, providing Python bindings to extend Lucene Core's capabilities.
  • Lucene uses inverted indexing to map terms to document locations, significantly speeding up search queries and enhancing performance.
  • Atlas Search, embedded in MongoDB Atlas, delivers a scalable full-text search feature using Apache Lucene, allowing for seamless integration of search capabilities without an additional system.
  • The mongot process is crucial for creating, managing, and updating Atlas Search indexes using Apache Lucene technology, ensuring they stay synchronized with MongoDB’s current state by monitoring change streams and applying updates promptly. It also handles Atlas Search queries directly, providing accurate and real-time search results.
  • Atlas Search Nodes in MongoDB Atlas are specialized, separated nodes focused solely on search functions via the mongot process. They provide workload isolation in dedicated (M10 or higher) sharded and unsharded clusters across various cloud providers.
  • An Atlas Search index can be on either a single field or multiple fields, preferably those used for sorting or filtering to speed up queries. Use dynamic mappings to automatically index all supported fields, though it may impact performance, or static mappings to selectively index specified fields, ignoring mismatched data types.
  • Atlas Search index limits vary by cluster tier. M0 clusters allow up to three indexes. For M10 and higher clusters, there are no restrictions on the number of indexes you can create.
  • There are no additional fees or charges when you enable Atlas Search on your Atlas cluster. However, you might observe an increase in resource utilization on the cluster depending on factors such as the size of the indexed collections or index definitions.
  • Atlas Search queries are formatted as stages within an aggregation pipeline. They incorporate the $search and $searchMeta stages, which are required to be the first stage in any query pipeline. These stages can also be integrated with other aggregation pipeline stages to enhance your query pipeline.
  • You can use the text operator together with the fuzzy operator. The fuzzy operator allows for searches that can match similar terms, accounting for possible typographical errors or variations in spelling. This enhances the search functionality by accommodating minor mistakes in the search query.
  • In systems like Apache Lucene, which supports Atlas Search, scores are dynamically calculated based on document relevance, with no upper limit. Higher scores indicate a closer match to the search criteria, effectively helping users quickly find the most relevant information.
  • The facet operator in Atlas Search structures search results into distinct categories based on criteria like price ranges, categories, or tags, facilitating easier navigation and organization of data.
  • You can explore Atlas Search using the MongoDB Atlas Search Playground. This user-friendly platform demonstrates the powerful features of Atlas Search without requiring a MongoDB Atlas account, cluster, or data collection. It lets you create search indexes and run queries in a simplified environment.

FAQ

What is Atlas Search and how is it different from MongoDB’s built-in $text search?Atlas Search is a Lucene-powered search capability integrated into MongoDB Atlas via the mongot process. It synchronizes with your data, exposes a rich set of search operators (text, phrase, wildcard, fuzzy, range, geo, equals/in/exists, autocomplete, compound, facet, etc.), and runs through aggregation stages ($search and $searchMeta). In contrast, MongoDB’s built-in $text index is basic and limited for complex queries. Atlas Search eliminates separate search systems, provides a single query API, and delivers relevance scoring and advanced analyzers.
What is an inverted index and why does Atlas Search use it?An inverted index maps terms (tokens) to the documents that contain them (like a book’s back-of-book index in reverse). Atlas Search uses Lucene’s inverted index so queries can quickly find relevant document IDs and then fetch the latest documents from the source collection. During indexing, analyzers tokenize and normalize text (e.g., case-folding, filtering) so searches are fast, accurate, and rankable by relevance.
How do I create an Atlas Search index?- Atlas CLI: Use atlas clusters search indexes create with a JSON config (name, database, collectionName, mappings, analyzers, synonyms, storedSource). - Atlas UI/Compass: Configure indexes visually from your cluster’s Search & Vector Search section. - mongosh (M10+): Use db.collection.createSearchIndex(). Tips: - Define static mappings (recommended for production) to control which fields are indexed and which analyzers are used. - Choose analyzers per field (e.g., lucene.standard) and optionally define custom analyzers.
When should I use static vs dynamic mappings?- Static mappings (recommended): You explicitly list fields to index. Benefits include better performance, lower disk usage, predictable schema handling, and fewer surprises with polymorphic data. - Dynamic mappings: Automatically index all supported field types. Convenient for exploration but can consume more disk and impact performance.
What are Atlas Search Nodes and why would I deploy them?Search Nodes are dedicated Atlas nodes that run mongot to handle search workloads, isolating search from transactional operations. In sharded clusters, you can deploy Search Nodes per shard (e.g., 2 per shard across 3 shards = 6 total). Atlas pairs each mongot with a mongod for syncing via change streams. Note: Local SSDs for Search Nodes need ~20% storage overhead for index operations.
When do I need to reindex and what storage should I plan for?Reindexing is required when you change an index mapping. Atlas builds a new index in the background, keeps the old one serving queries, then switches seamlessly. Plan at least 125% free disk space relative to the current index size. Index rebuilds also happen when: - Adding or scaling Search Nodes - Certain internal mongot changes Atlas Search is eventually consistent; mongot uses change streams to catch up.
What is the difference between $search and $searchMeta?- $search: Must be the first stage; returns matching documents with optional relevance scores ($meta: "searchScore"), sorting, highlighting, pagination (searchAfter/searchBefore), and more. - $searchMeta: Must be the first stage; returns metadata only (e.g., counts, facet results). You can also access metadata after $search via the $$SEARCH_META aggregation variable in subsequent stages.
Which search operators and collectors are available, and what are common use cases?- Operators: text, phrase (proximity), wildcard, regex, fuzzy, range, near, equals, in, exists, queryString, autocomplete, geoWithin, geoShape, embeddedDocument, compound. - Collector: facet (stringFacet, numberFacet, dateFacet) for grouped counts. Common use cases: - Fuzzy/wildcard for misspellings/unknown fragments - Phrase with slop for proximity searches - Range/near for numbers/dates/geo - Facets for filter panels and analytics - Compound to combine must/should/filter logic
What are key limits, costs, and operational considerations for Atlas Search?- Index limits: M0 tiers support up to 3 search indexes; M10+ has no hard index count limit. - Index definition: JSON must be ≤ 3 KB; index builds with > 300 fields fail. - Resource use: Index creation is resource-intensive and may impact cluster performance during builds. - Costs: No separate “search” fee, but search increases cluster resource usage. - Pipeline caveat: If you use $out on a collection with a search index, you must drop and recreate the index (prefer $merge where possible).
What is the Atlas Search Playground and what are its limitations?The Playground lets you try Atlas Search without an account or cluster. You can build indexes and run queries in a browser. Limitations: - No Atlas Vector Search - Single collection (no $lookup/$unionWith) - Environment isn’t persistent; shareable snapshot URLs expire after 30 days - Data limits: ≤ 500 docs, ≤ 100 KB per import file, and total environment size ≤ 300 KB

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • MongoDB 8.0 in Action, Third Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • MongoDB 8.0 in Action, Third Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • MongoDB 8.0 in Action, Third Edition ebook for free