How to Index Fields for Autocompletion
On this page
You can use the Atlas Search autocomplete
type to index text values in
string fields for autocompletion. You can configure an autocomplete
type to satisfy a variety of use cases. To learn more about the
configuration options available for the autocomplete
type, such as
tokenization strategy and diacritic folding, see
Configure autocomplete
Field Properties. You can query fields
indexed as autocomplete
type only 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 Atlas 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 Atlas Search Index Performance Considerations.
Atlas Search doesn't dynamically index
fields of type autocomplete
. You must use static mappings to index autocomplete
fields. You can
use the Visual Editor or the JSON Editor in the Atlas UI
to index fields of type autocomplete
.
Define the Index for the autocomplete
Type
To define the index for the autocomplete
type, choose your preferred
configuration method in the Atlas UI and then select the
database and collection.
Configure autocomplete
Field Properties
The Atlas Search autocomplete
type takes the following parameters:
Option | Type | Necessity | Description | Default | |
---|---|---|---|---|---|
type | string | required | Human-readable label that identifies this field type. Value must
be string. | ||
analyzer | string | optional | Name of the analyzer to use with this
autocomplete mapping. You can use any Atlas Search analyzer except the
This option isn't available in the Visual Editor. | lucene.standard | |
maxGrams | 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 maxGrams value, Atlas Search
truncates the tokens to the maxGrams length. | 15 | |
minGrams | int | optional | Minimum number of characters per indexed sequence. We
recommend 4 for the minimum value. A value that is less
than 4 could impact performance because the size of the
index can become very large. We recommend the default value of
2 for edgeGram only. | 2 | |
tokenization | enum | optional | Tokenization strategy to use when indexing the field for autocompletion. Value can be one of the following:
When tokenized with a NoteIndexing a field for autocomplete with an | edgeGram | |
foldDiacritics | boolean | optional | Flag that indicates whether to include or remove diacritics from the indexed text. Value can be one of the following:
| true |