Search Indexes¶
A search index is a data structure that maps the terms in your documents to the documents that contain them. Instead of scanning every document in a collection, a search query looks up terms in the index and retrieves only the matching documents, along with metadata such as term positions and relevance data.
- Search Indexes are maintained by the
mongotprocess using Apache Lucene. - Search queries use the aggregation pipeline stages
$searchand$searchMeta. - When you create a search index, Percona Search for MongoDB transforms your data into a sequence of tokens or terms.
How Search Indexes work¶
When you create a search index on a collection, mongot does the following:
- Performs an initial sync, reading the collection data from mongod and building the Lucene index.
- Opens a change stream on the collection to watch for inserts, updates, and deletes.
- Applies those changes to the index continuously, keeping it in sync with the collection.
Types of Search Indexes¶
Percona Search for MongoDB supports two index types:
- Search indexes power full-text search with the
$searchand$searchMetastages. They support text analyzers, relevance-based scoring, autocomplete, faceting, and highlighting. - Vector search indexes power semantic and similarity search with the
$vectorSearchstage. They index vector embeddings that you store in your documents and support approximate nearest neighbor (ANN) search.
Field mappings¶
A search index definition specifies which fields to index and how to index them. You can choose between two mapping strategies:
-
Dynamic mapping indexes all fields of supported types automatically, including fields added to documents later. Fields can be indexed based on the default set of types or by configuring a
typeSet. -
Static mapping indexes only the fields you explicitly define. To use static mappings to configure index options for only some fields, set
mappings.dynamicto false and specify the field name, data type , and other configuration options for each field that you want to index. You can specify the fields in any order.