index-definitions
For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt
<!-- Tab options on this page. Append to the .md URL to filter: ?tabs=<id,...> select specific tabs (e.g. ?tabs=nodejs,shell) ?allTabs=true include every tab (no param) default: one tab per tabset
Available tabs: other tabs: basic, expanded -->
Index Reference
A MongoDB Search index is a data structure that maps documents from your cluster to the terms that are extracted from those documents. MongoDB Search indexes enable efficient full-text searches of your database.
When you define a MongoDB Search index, you can use [static or dynamic mappings](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-fts-field-mappings to specify which fields or field types you want to index in your collection. You can also use [analyzers](https://www.mongodb.com/docs/search/indexes/analyzers/overview.md#std-label-analyzers-ref to define how MongoDB Search extracts searchable tokens from string fields or query strings. Finally, you can apply additional configuration options in your index definition to improve the performance and accuracy of your MongoDB Search query, including options to [store source fields in your index](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition, or [define synonym mappings.](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-fts-field-mappings
To learn how to define a MongoDB Search index according to your query requirements, see [Manage MongoDB Search Indexes](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-ref-create-index. Once you define your MongoDB Search index, you can add the index to your cluster with the [Create a MongoDB Search Index](https://www.mongodb.com/docs/search/tutorial.md#std-label-create-fts-index tutorial. To learn how to view, edit, update, or delete your MongoDB Search index, see [Supported Clients.](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-fts-manage-indexes
This page describes the JSON (Javascript Object Notation) syntax and definition options for a MongoDB Search index.
Syntax
Basic
{
"mappings": {
"dynamic": <boolean> | { <field-types-definition> } ,
"fields": { <field-definition> }
}
}
Options
| Field | Type | Necessity | Description |
|---|---|---|---|
analyzer |
String | Optional | Specifies the [analyzer](https://www.mongodb.com/docs/search/indexes/analyzers/overview.md#std-label-analyzers-ref to apply to string fields when indexing. If you set this only at the top and do not specify an analyzer for the fields in the index definition, MongoDB Search applies this analyzer to all the fields. To use a different analyzer for each field, you must specify a different analyzer for the field. If omitted, defaults to [Standard Analyzer.](https://www.mongodb.com/docs/search/indexes/analyzers/standard.md#std-label-ref-standard-analyzer |
analyzers |
Array of [Custom Analyzers](https://www.mongodb.com/docs/search/indexes/analyzers/custom.md#std-label-custom-analyzers | Optional | Specifies the [Custom Analyzers](https://www.mongodb.com/docs/search/indexes/analyzers/custom.md#std-label-custom-analyzers to use in this index. |
mappings |
Object | Required | Specifies how to index fields at different paths for this index. |
mappings.``dynamic |
Boolean or Object | Optional | Enables dynamic mapping of field types or configures fields individually for this index. Value must be one of the following: boolean - set to true to recursively index all indexable field types or set to false to not dynamically index any of the indexable field types.; object - specify the typeSet to use for recursively indexing all indexable field types. To learn more, see mappings.dynamic.typeSet. If omitted, defaults to false. If set to false, you must define the individual fields to statically index using mappings.fields. You can also configure fields individually to override default settings using mappings.fields. Settings for fields in mappings.fields override default settings. IMPORTANT: MongoDB Search automatically indexes all dynamically indexable field types in a document. MongoDB Search also recursively indexes all nested documents under the document, unless you explicitly override by setting dynamic to false. You can also configure dynamic indexing to only index specified field types using typeSets. To learn about the field types that you can enable for dynamic mappings, see [MongoDB Search Field Types.](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-bson-data-types For example index configurations, see [Examples](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-index-config-example |
mappings.``dynamic.``typeSet |
String | Optional | References the name of the typeSets object that contains the list of field types to automatically and recursively index. Mutually exclusive with mappings.dynamic boolean flag. |
mappings.``fields |
Object | Conditional | Specifies the fields that you want to index. Required only if dynamic mapping is false. You can't index fields that contain the dollar ($) sign at the start of the field name. To learn more, see [Define Field Mappings for a MongoDB Search Index.](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-fts-field-mappings |
searchAnalyzer |
String | Optional | Specifies the [analyzer](https://www.mongodb.com/docs/search/indexes/analyzers/overview.md#std-label-analyzers-ref to apply to query text before searching with it. If omitted, defaults to the analyzer that you specify for the analyzer option. If you omit both the searchAnalyzer and the analyzer options, defaults to the [Standard Analyzer.](https://www.mongodb.com/docs/search/indexes/analyzers/standard.md#std-label-ref-standard-analyzer |
numPartitions |
Integer | Optional | Specifies the number of sub-indexes to create if the document count exceeds two billion. The following values are valid: 1, 2, 4. If omitted, defaults to 1. To use index partitions, you must have search nodes deployed in your cluster. |
storedSource |
Boolean or [Stored Source Definition](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition | Optional | Specifies fields in the documents to store for query-time look-ups using the [returnedStoredSource](https://www.mongodb.com/docs/search/query/return-stored-source.md#std-label-fts-return-stored-source-option option. You can store fields of all [MongoDB Search Field Types](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-bson-data-chart on MongoDB Search. Value can be one of the following: true, to store all fields; false, to not store any fields; [Object](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-document that specifies the fields to include or exclude from storage storedSource is only available on clusters running MongoDB 7.0+. If omitted, defaults to false. To learn more, see [Define Stored Source Fields in Your MongoDB Search Index.](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition |
synonyms |
Array of [Synonym Mapping Definition](https://www.mongodb.com/docs/search/indexes/synonyms.md#std-label-synonyms-ref | Optional | Specifies the synonym mappings to use in your index. An index definition can have only one [synonym mapping.](https://www.mongodb.com/docs/search/indexes/synonyms.md#std-label-synonyms-ref To learn more, see [Define Synonym Mappings in Your MongoDB Search Index.](https://www.mongodb.com/docs/search/indexes/synonyms.md#std-label-synonyms-ref |
typeSets |
Array of objects | Optional | Specifies the [typeSets](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-fts-configure-dynamic-mappings to use in this index for dynamic mappings. |
typeSets.``[n].name |
String | Required | Specifies the name of the typeSet configuration. |
typeSets.``[n].types |
Array of objects | Required | Specifies the field types, one per object, to index automatically using dynamic mappings. |
typeSets.``[n].types.``[n].type |
String | Required | Specifies the field type to automatically index. To learn more about the field types that you can configure for dynamic mapping, see [Configure a typeSet.](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-fts-configure-dynamic-mappings |
Troubleshoot Indexes
mongot Process Not Installed or Running
The following error is returned if you run $search queries when the MongoDB Search mongot process isn't installed or running:
MongoError: Remote error from mongot :: caused by :: Error connecting to localhost:28000.
The mongot process is installed only when the first MongoDB Search index is defined. If you don't have any MongoDB Search index in your cluster, create at least one MongoDB Search index to resolve this error.
Learn More
To learn how to define a MongoDB Search index to meet your MongoDB Search query needs, see [Manage MongoDB Search Indexes.](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-ref-create-index
To learn how to add an index to your cluster, see [Create a MongoDB Search Index.](https://www.mongodb.com/docs/search/tutorial.md#std-label-create-fts-index
To learn more about the available index configuration options, see the following reference pages:
-
[Process Data with Analyzers](https://www.mongodb.com/docs/search/indexes/analyzers/overview.md#std-label-analyzers-ref
-
[Define Field Mappings for a MongoDB Search Index](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-fts-field-mappings
-
[Define Stored Source Fields in Your MongoDB Search Index](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition
-
[Define Synonym Mappings in Your MongoDB Search Index](https://www.mongodb.com/docs/search/indexes/synonyms.md#std-label-synonyms-ref
