Join us Sept 17 at .local NYC! Use code WEB50 to save 50% on tickets. Learn more >
MongoDB Event
Docs Menu
Docs Home
/
Atlas

MongoDB Search Overview

MongoDB Search is an embedded full-text search that gives you a seamless, scalable experience for building relevance-based app features and eliminates the need to run a separate search system alongside your database.

You can use MongoDB Search for fine-grained text indexing and querying of data on your cluster. MongoDB Search provides several kinds of text analyzers, a rich query language to create complex search logic, customizable score-based results ranking, and advanced search features for your applications like autocomplete, pagination, and faceting.

Get Started with MongoDB Search

MongoDB Search supports diverse use cases including the following:

The following concepts form the basis of MongoDB Search and are essential to optimize your application.

Search queries consult a search index to return a set of results. Search queries are different than traditional database queries, as they are intended to meet more general information needs. Where a database query must follow a strict syntax, search queries can be used for simple text matching, but can also look for similar phrases, number or date ranges, or use regular expressions or wildcards.

MongoDB Search queries take the form of an aggregation pipeline stage. MongoDB Search provides $search and $searchMeta stages, which can be used in conjunction with other aggregation pipeline stages in your query pipeline. MongoDB Search provides query operators and collectors that you can use inside these aggregation pipeline stages.

To learn more, see Queries and Indexes.

In the context of search, an index is a data structure that categorizes data in an easily searchable format. Search indexes enable faster retrieval of documents that contain a given term without having to scan the entire collection. While both MongoDB Search indexes and MongoDB Indexes make data retrieval faster, note that they are not the same. Like the index in the back of a book, a search index is a mapping between terms and the documents that contain those terms. Search indexes also contain other relevant metadata, such as the positions of terms in documents.

You can create an MongoDB Search index on a single field or on multiple fields by using static mappings. Alternatively, you can enable dynamic mappings to automatically index all the dynamically indexable fields in your documents. You can create MongoDB Search indexes on polymorphic data and embedded documents, or for specific use-cases like search-as-you-type or faceted search.

To learn more, see Supported Clients.

When creating a search index, data must first be transformed into a sequence of tokens or terms. An analyzer facilitates this process through steps including:

  • Tokenization: Breaking up words in a string into indexable tokens. For example, dividing a sentence by whitespace and punctuation.

  • Normalization: Organizing data so that it is consistently represented and easier to analyze. For example, transforming text to lower case or removing unwanted words called stop words.

  • Stemming: Reducing words to their root form. For example, ignoring suffixes, prefixes, and plural word forms.

The specifics of tokenization are language-specific and can require making additional choices. Which analyzer to use depends on your data and application.

MongoDB Search provides some built-in analyzers. You can also create your own custom analyzer. You can specify alternate analyzers using multi analyzer.

To learn more, see Process Data with Analyzers.

Each document in the query results receives a relevancy score that enables query results to be returned in order from the highest relevance to the lowest. In the simplest form of scoring, documents score higher if the query term appears frequently in a document and lower if the query term appears across many documents in the collection. Scoring can also be customized. Tailoring search to a specific domain often means customizing the relevance-based default score by boosting, decaying, or modifying it in other ways.

To learn more, see Score Documents.

For a hands-on experience creating MongoDB Search indexes and running MongoDB Search queries against sample data, try the MongoDB Search Quick Start.

On this page