You can use the MongoDB Search autocomplete type to index text values in
string fields for autocompletion. You can query fields indexed as
autocomplete type using the autocomplete operator.
You can also use the autocomplete type to index:
Fields whose value is an array of strings. To learn more, see How to Index the Elements of an Array.
String fields inside an array of documents indexed as the embeddedDocuments type.
Tip
If you have a large number of documents and a wide range of data
against which you want to run MongoDB Search queries using the
autocomplete operator, building this index can take
some time. Alternatively, you can create a separate index with only
the autocomplete type to reduce the impact on other indexes and
queries while the index builds.
To learn more, see MongoDB Search Index Performance Considerations.
autocomplete type is not included in the dynamic mapping by default. To index fields
as autocomplete type, you can use static mappings or configure a typeSet to include autocomplete in dynamic mapping.
Define the Index for the autocomplete Type
Configure autocomplete Field Properties
The MongoDB Search autocomplete type takes the following parameters:
Option | Type | Necessity | Description | Default | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| string | required | Human-readable label that identifies this field type. Value must
be | |||||||||||||||||||||||||||||||||||||||||||||||||
| string | optional | Name of the analyzer to use with this
autocomplete mapping. You can use any MongoDB Search analyzer except the
|
| ||||||||||||||||||||||||||||||||||||||||||||||||
| int | optional | Maximum number of characters per indexed sequence. The
value limits the character length of indexed tokens. When you
search for terms longer than the NoteWe recommend setting the |
| ||||||||||||||||||||||||||||||||||||||||||||||||
| int | optional | Minimum number of characters per indexed sequence. We
recommend |
| ||||||||||||||||||||||||||||||||||||||||||||||||
| enum | optional | Tokenization strategy to use when indexing the field for autocompletion. Value can be one of the following:
When tokenized with a Indexing a field for autocomplete with an For the specified tokenization strategy, MongoDB Search applies the
following process to concatenate sequential tokens before
emitting them. This process is sometimes referred to as
"shingling". MongoDB Search emits tokens between
|
| ||||||||||||||||||||||||||||||||||||||||||||||||
| boolean | optional | Flag that indicates whether to perform normalizations such as including or removing diacritics from the indexed text. Value can be one of the following:
|
| ||||||||||||||||||||||||||||||||||||||||||||||||
| string | optional | Name of the similarity algorithm to use with this string mapping
when scoring with the autocomplete
operator. Value can be one of the following: To learn more about the available similarity algorithms, see Score Details. |
|
Try an Example for the autocomplete Type
Learn More
To learn more about the autocomplete operator and see example queries,
see autocomplete.
For examples that demonstrate how to run case-insensitive, prefix, starts with, and contains queries using regex expressions, see Use MongoDB Search Instead of Regex Queries.