How to Index Fields in Arrays of Objects and Documents
On this page
Note
The Atlas Search embeddedDocuments
index option, embeddedDocument operator, and
embedded
scoring option are in preview. When an Atlas Search
index on a replica set or single MongoDB shard reaches Lucene's two
billion document limit, Atlas Search doesn't index new documents or apply
updates to existing documents for that index. A solution to accommodate
this limitation will be in place when this feature is generally
available. To troubleshoot any issues related to using this feature,
contact Support.
You can use the Atlas Search embeddedDocuments
type to index fields in
documents and objects that are elements of an array. Atlas Search indexes
embedded documents independent of their parent document. Each indexed
document contains only fields that are part of the embedded document
array element. You can use only the embeddedDocument
operator to query fields indexed as embeddedDocuments
type.
Atlas Search doesn't dynamically index
fields of type embeddedDocument
. You must use static mappings to index embeddedDocument
fields. You can
use the Visual Editor or the JSON Editor in the Atlas UI
to index fields of type embeddedDocument
.
Review embeddedDocuments
Type Limitations
Note
Atlas Search doesn't support indexing more than two billion
index objects, where each indexed embedded document counts as a single
object. Using the embeddedDocuments
field type can result in indexing
objects over this limit, which causes an index to transition to a failed state.
If your collection has large arrays that might generate two billion objects, you
must shard any clusters that contain
indexes with the embeddedDocuments
type.
The following limitations apply:
You can use
embeddedDocuments
only on fields with up to5
levels of nesting. AnembeddedDocuments
field can't have more than4
parentembeddedDocuments
fields.You can't use
embeddedDocuments
for date or numeric faceting.You can't define a field inside the
embeddedDocuments
type as the knnVector type.You can't highlight fields or children of fields indexed as the
embeddedDocuments
type.You can't index children of fields indexed as the
embeddedDocuments
type as the token type.
Define the Index for the embeddedDocument
Type
To define the index for the embeddedDocument
type, choose your preferred
configuration method in the Atlas UI and then select the
database and collection.
Configure embeddedDocument
Field Properties
The Atlas Search embeddedDocuments
type takes the following parameters:
Field | Type | Necessity | Description | Default |
---|---|---|---|---|
type | string | Required | Human-readable label that identifies the field type.
Value must be embeddedDocuments . | |
dynamic | boolean | Optional | Flag that specifies whether to index every dynamically indexable field in the document. Value can be one of the following:
| false |
fields | document | Optional | Fields to index. If If NoteAtlas Search doesn't support indexing facet fields as part of an
| {} |
Try an Example for the embeddedDocument
Type
The following index definition example uses the sample_supplies.sales 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.