For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Whitespace Analyzer

The whitespace analyzer divides text into searchable terms (tokens) wherever it finds a whitespace character. It leaves all text in its original letter case.

If you select Refine Your Index, the Atlas UI displays a section titled View text analysis of your selected index configuration within the Index Configurations section. If you expand this section, the Atlas UI displays the index and search tokens that the whitespace analyzer generates for each sample string. You can see the tokens that the whitespace analyzer creates for a built-in sample document and query string when you create or edit an index in the Atlas UI Visual Editor.

Important

MongoDB 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.

The following example index definition specifies an index on the title field in the sample_mflix.movies collection using the whitespace analyzer. To follow along with this example, load the sample data on your cluster and either use mongosh or navigate to the Create a Search Index page in the Atlas UI following the steps in the Create a MongoDB Search Index tutorial.

Then, using the movies collection as your data source, follow the example procedure to create an index from mongosh or the Atlas UI Visual Editor or JSON editor.


The following query searches for the term Lion's in the title field.

MongoDB Search returns these documents by doing the following for the text in the title field using the lucene.whitespace analyzer:

  • Retain the original letter case for the text.

  • Divide the text into tokens wherever it finds a whitespace character.

The following table shows the tokens (searchable terms) that MongoDB Search creates using the Whitespace Analyzer and, by contrast, the Simple Analyzer and Keyword Analyzer for the documents in the results:

Title
Whitespace Analyzer Tokens
Simple Analyzer Tokens
Keyword Analyzer Tokens

The Lion's Mouth Opens

The, Lion's, Mouth, Opens

the, lion, s, mouth, opens

The Lion's Mouth Opens

The index that uses whitespace analyzer is case-sensitive. Therefore, MongoDB Search is able to match the query term Lion's to the token Lion's created by the whitespace analyzer.