Docs Menu

Docs HomeLaunch & Manage MongoDBMongoDB Atlas

How to Index String Fields For Faceted Search

On this page

  • Define the Index for the stringFacet Type
  • Configure Properties for the stringFacet Type
  • Try an Example for the stringFacet Type

You can use the Atlas Search stringFacet type to index string fields for faceting, which allows you to run a facet query on that field. Atlas Search doesn't apply the analyzer when indexing string fields for faceting.

Atlas Search only supports facet queries against fields indexed as the stringFacet type. To perform a normal search also on the same field, you must index the field as type string also.

To facet on string fields in embedded documents, you must index the parent fields as the document type. When you facet on a string field inside embedded documents, Atlas Search returns facet count for only the number of matching parent documents.

Atlas Search doesn't dynamically index string values for faceting. You must use static mappings to index string values for faceting. You can use the Visual Editor or the JSON Editor in the Atlas UI to index date fields as the stringFacet type.

To define the index for the stringFacet type, choose your preferred configuration method in the Atlas UI and then select the database and collection.

The Atlas Search stringFacet type has the following parameters:

UI Field Name
JSON Option
Type
Necessity
Description
Data Type
type
string
Required
Human-readable label that identifies this field type. Value must be stringFacet.

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.

Tip

See also: Additional Index Definition Examples

← How to Index String Fields