How to Index String Fields
On this page
You can use the Atlas Search string
type to index string fields. You can use the Atlas Search
phrase, queryString, span,
text, wildcard, regex, and
moreLikeThis operators to query fields indexed as the
string
type.
If you enable dynamic mappings, Atlas Search
automatically indexes fields of type string
. You can
use the Visual Editor or the JSON Editor in the Atlas UI to
index fields as the string
type.
Review the Limitations for the string
Type
You can't use the Atlas Search string
type to index fields for
facet or autocomplete queries. You can't use
the string
type to index fields for sorting Atlas Search results. Instead,
you must use static mappings to index
the string fields as the following types:
stringFacet type to run a facet query on string fields. Note that Atlas Search doesn't dynamically index string fields for faceting.
autocomplete type to run autocomplete operator queries on string fields. Note that Atlas Search doesn't dynamically index string fields for autocompletion.
token type to sort the Atlas Search results by the string field. Atlas Search doesn't dynamically index string fields for sorting the results.
Atlas Search won't index string fields that exceed 32766 bytes in size.
Define the Index for the string
Type
To define the index for the string
type, choose your preferred
configuration method in the Atlas UI and then select the
database and collection.
Configure string
Field Properties
The Atlas Search string
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 | ||
searchAnalyzer | string | Optional | Analyzer to use when querying the field. If you don't specify a value, inherits an analyzer by default in the following order: | |
indexOptions | string | Optional | Amount of information to store for the indexed field. Value can be one of the following:
| offsets |
store | boolean | Optional | Flag that indicates whether to store the exact document text as
well as the analyzed values in the index. Value can be NoteTo reduce the index size and performance footprint, we
recommend setting | true |
ignoreAbove | int | Optional | Maximum number of characters in the value of the field to
index. Atlas Search doesn't index if the field value is greater than
the specified number of characters. | |
multi | String Field Definition | Optional | String field to index with the name of the alternate
analyzer specified in the multi object. To learn more about
specifying the multi object, see Multi Analyzer
and example below. | |
norms | string | Optional | String that specifies whether to include or omit the field length in the result when scoring. The length of the field is determined by the number of tokens produced by the analyzer for the field. Value can be one of the following:
If value is If value is | include |
Try an Example for the string
Type
The following index definition example uses the sample_mflix.movies collection. If you have the sample data already loaded on your cluster, you can use the Visual Editor or JSON Editor in the Atlas UI to configure the index. After you select your preferred configuration method, select the database and collection, and refine your index to add field mappings.