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.
token type to find an exact match for queries using equals, in, and range operators. Atlas Search doesn't dynamically index string fields as
token
type for querying using these operators.
Important
Atlas Search won't index string fields where analyzer tokens exceed 32766 bytes in size. If using the keyword analyzer, string fields which exceed 32766 bytes will not be indexed.
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.
Click Refine Your Index to configure your index.
In the Field Mappings section, click Add Field to open the Add Field Mapping window.
Click Customized Configuration.
Select the field to index from the Field Name dropdown.
Note
You can't index fields that contain the dollar (
$
) sign at the start of the field name.Click the Data Type dropdown and select String.
(Optional) Expand and configure the String Properties for the field. To learn more, see Configure
string
Field Properties.(Optional) Click Add Multi Field to configure the following alternate analyzer settings for that field:
Enter a name for the alternate analyzer in the Multi Field Name field.
Configure the string field properties for the alternate analyzer under Multi Field Properties. To learn more, see Configure
string
Field Properties.(Optional) Click Add Another Mult Field and repeat steps 1 and b to configure more analyzers for the field.
Click Add.
The following is the JSON syntax for the string
type.
Replace the default index definition with the following. To learn more
about the fields, see Field Properties.
{ "mappings": { "dynamic": true|false, "fields": { "<field-name>": { "type": "string", "analyzer": "<atlas-search-analyzer>", "searchAnalyzer": "<atlas-search-analyzer>", "indexOptions": "docs|freqs|positions|offsets", "store": true|false, "ignoreAbove": <integer>, "multi": {<string-field-definition>}, "norms": "include|omit" } } } }
Configure string
Field Properties
The Atlas Search string
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 | ||
| 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: | |
| string | Optional | Amount of information to store for the indexed field. Value can be one of the following:
|
|
| boolean | Optional | Flag that indicates whether to store the exact document text as
well as the analyzed values in the index. Value can be To reduce the index size and performance footprint, we recommend setting |
|
| 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. | |
| String Field Definition | Optional | String field to index with the name of the alternate
analyzer specified in the | |
| 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 |
|
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.
The following index definition indexes string values in the
title
field as Atlas Search string
type:
In the Add Field Mapping window, select title from the Field Name dropdown.
Click the Data Type dropdown and select String.
Review the default settings for the String Properties.
Click Add.
Replace the default index definition with the following index definition.
{ "mappings": { "dynamic": false, "fields": { "title": { "type": "string" } } } }
The following index definition indexes string values in the
fullplot
field with the lucene.english
and lucene.french
analyzers in addition to the default lucene.standard
analyzer:
In the Add Field Mapping window, select fullplot from the Field Name dropdown.
Click the Data Type dropdown and select String.
Review the default settings for the String Properties.
Click Add Multi Field, enter
english
in the Multi Field Name field, and configure the following Multi Field Properties:Index Analyzer
Select
lucene.english
underlucene.language
.Search Analyzer
Select
lucene.english
underlucene.language
.Click Add Another Multi Field, enter
french
in the Multi Field Name field, and configure the following Multi Field Properties:Index Analyzer
Select
lucene.french
underlucene.language
.Search Analyzer
Select
lucene.french
underlucene. language
.Click Add.
Replace the default index definition with the following index definition.
{ "mappings": { "dynamic": false, "fields": { "fullplot": { "type": "string", "multi": { "english": { "type": "string", "analyzer": "lucene.english" }, "french": { "type": "string", "analyzer": "lucene.french" } } } } } }