liveBook · Manning

Keyword search index

As explained in MongoDB 8.0 in Action, Third Edition

A search index is an index structure that organizes searchable content for efficient full-text or relevance-based retrieval.

A keyword search index organizes searchable content so a query can retrieve relevant documents efficiently. In Atlas Search, the Lucene-powered index maps terms to document identifiers and records metadata such as term positions. Create the index before querying a collection with Atlas Search. section 11.3.3

Choose the index type for the search behavior you need. A traditional MongoDB text index supports keyword queries through $text, including relevance scores, but does not efficiently support partial-value searches such as regular expressions. Atlas Search is the recommended choice for fuller search capabilities; its indexes use additional disk space and memory. section 7.2.4 section 11.3.3

Configure an Atlas Search index around the fields users search, sort, or filter:

  • Use static mappings to name the fields and their types. This is preferred for production because it avoids indexing unnecessary fields, saves disk space, and can improve performance. section 11.3.3
  • Use dynamic mappings to index supported fields automatically when convenience matters, such as in a local test environment. Expect greater disk use and a possible performance impact. section 11.3.3 section 13.5.1
  • Set analyzers for indexed strings when the default treatment of search terms does not fit the intended queries. section 11.3.3

Create and check a local index

In a local Atlas cluster, run `db.inspections.createSearchIndex("LocalSearchIndex", { mappings: { dynamic: true } })`. Then run `db.inspections.getSearchIndexes()` and check for `status: 'READY'` and `queryable: true`. A query can name `LocalSearchIndex` in the first `$search` aggregation stage; the inspections example searches `result` and `business_name`, allows two typographical edits, then filters and sorts by search score. section 13.5.1 section 11.8

For a cloud deployment, define a static mapping in a JSON file and create it with `atlas clusters search indexes create --clusterName <name> --file index-definition.json --output json`. Index builds are resource-intensive, so check status before querying. M0 clusters allow three Atlas Search indexes; M10 and higher have no index-count restriction stated here. Enabling Atlas Search adds no separate fee, but increased resource use can still matter. section 11.4

The index must also stay current as documents change: the `mongot` process manages Atlas Search indexes and applies updates from MongoDB change streams. This search workload is separate from core database operations. section 11.8 section 13.6

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains term-to-document mappings, field configuration, creation, readiness checks, and resource trade-offs without implementing the index structure.
Examples
Uses an inspections collection for CLI and local index creation, then fuzzy search with filters and search-score sorting.
What it assumes
Assumes a usable Atlas cluster and sample data; requires Docker for the local Atlas workflow.
What you can do after
Operate/configure it with Atlas CLI or MongoDB methods, verify readiness, and query the named index with `$search`.
How it connects
Connects inverted indexing with analyzers, static and dynamic mappings, aggregation pipelines, change streams, and relevance scoring.

Also explained in

Compare how 3 books explain keyword search index →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.