liveBook · Manning

createSearchIndexes database command

As explained in MongoDB 8.0 in Action, Third Edition

db.collection.createSearchIndex() is a mongosh collection helper method that creates an Atlas Search index from a name and configuration document.

The createSearchIndexes database command creates Atlas Search indexes. In mongosh, db.collection.createSearchIndex() wraps the command, accepting an index name and a configuration document. The index makes collection fields available to full-text queries. section 13.5 section 11.6

To create and use a full-text index:

  • Choose a mapping. Dynamic mapping is convenient for a local test; static mapping indexes only predefined fields and can improve search performance, prevent schema conflicts, and keep field handling consistent. section 13.5.1 section 11.4
  • In mongosh, select the database and call createSearchIndex() on the collection with an index name and mappings document. section 11.6 section 13.5.1
  • Check db.collection.getSearchIndexes() for status READY and queryable: true before using the named index in a $search query. section 13.5.1
use sample_training
db.inspections.createSearchIndex(
   "LocalSearchIndex",
   { mappings: { dynamic: true } }
)

This mongosh example creates LocalSearchIndex on sample_training.inspections with dynamic mapping for a local Atlas cluster. section 13.5.1

For hosted Atlas deployments, these mongosh search-index management commands require an M10-or-higher cluster. The Atlas CLI offers a separate creation path using an index-definition file. Once an index exists, related mongosh methods can update or drop it; getSearchIndexes() can inspect its status. section 11.6 section 11.4 section 13.5.1

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Shows the wrapper’s arguments and a local creation-and-verification workflow, but does not detail the database command’s direct syntax.
Examples
Creates LocalSearchIndex on sample_training.inspections with dynamic mapping, checks its status, and uses it in a fuzzy full-text query.
What it assumes
Assumes access to an Atlas deployment and a collection; shows the mongosh call needed to create a local test index.
What you can do after
Operate/configure it: create a local full-text search index with mongosh and verify that it is ready and queryable.
How it connects
Connects Atlas Search indexes to mongosh, dynamic and static mappings, $search queries, and index-management methods.

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.