Skip to main content

πŸ“˜ Index configuration

Documents are indexed in Lucene using a flexible configuration specification.

Supported types​

The type of a field determines how it can be indexed, and thus how it can be searched.

Most field types are supported, including all the basic types such as booleans, dates, numerics, and strings, as well as ObjectID, UUID, GeoJSON types. Null values are also supported implicitly.

Mapping​

A JSON-formatted index configuration mapping specifies which fields are indexed.

Fields can be mapped explicitly, by name (and path), or dynamically, or a combination of both.

Dynamic mapping​

An index configuration defaults to a fully dynamic mapping:

{
"mappings": {
"dynamic": true
}
}

A dynamic mapping indexes all dynamically supported fields automatically. Dynamic mapping alleviates having to specify every field explicitly, which would be arduous in situations where there are many fields, or where new fields could be added to documents over time.

You can configure an entire index to use dynamic mappings, or have fields only within nested documents, be dynamically mapped.

Not all data types are supported with dynamic mapping. Most notably, GeoJSON fields require explicit mapping.

If mappings.dynamic is set to false, at least one field must be explicitly mapped.

Static/explicit field mapping​

To explicitly specify a fields mapping, it is listed in a mappings.fields section of the configuration.

An example:

{
"mappings": {
"dynamic": false,
"fields": {
"in_stock": [
{
"type": "boolean"
}
]
}
}
}

Using that mapping, this document would only have the in_stock field indexed, not the name field.

{
_id: 1,
name: "Product One",
in_stock: true
}

A field path/name can be mapped as an array of supported types. When the type of the document field matches an index mapping for that type, it will be indexed as appropriate for that particular type.

Configuring an Atlas Search index​

Outside of the Playground, you have several options to set up and configure a persistent Atlas Search index.

  • Atlas Search Visual Editor or JSON Editor
  • via Compass
  • Atlas CLI
  • Driver commands

The Atlas Search Visual Editor is a good place to start, to become familiar with the syntax and options available.

Resources​