diff --git a/source/includes/model-data/indexes.py b/source/includes/model-data/indexes.py index 70194b2..33649ad 100644 --- a/source/includes/model-data/indexes.py +++ b/source/includes/model-data/indexes.py @@ -3,6 +3,7 @@ from django.db.models import Q, F from django_mongodb_backend.models import EmbeddedModel from django_mongodb_backend.fields import EmbeddedModelField, ArrayField +from django_mongodb_backend.indexes import SearchIndex class Nutrition(EmbeddedModel): calories = models.IntegerField(default=0) @@ -60,6 +61,17 @@ class Meta: ] # end-embedded +# start-atlas-search +class Meta: + db_table = "recipes" + indexes = [ + SearchIndex( + fields=["title"], + name="title_search_idx", + ) + ] +# end-atlas-search + # start-partial class Meta: db_table = "recipes" diff --git a/source/limitations-upcoming.txt b/source/limitations-upcoming.txt index 953edf9..34b2a4c 100644 --- a/source/limitations-upcoming.txt +++ b/source/limitations-upcoming.txt @@ -54,9 +54,7 @@ Index Support - Planned GA Support * - Atlas Search and Atlas Vector Search indexes - - *Unsupported*. You cannot use the Django - Indexes API to create these indexes, but you can use - the PyMongo Driver by :ref:`exposing your MongoClient `. + - ✓ - ✓ * - Compound indexes diff --git a/source/model-data/indexes.txt b/source/model-data/indexes.txt index d092f22..84120e5 100644 --- a/source/model-data/indexes.txt +++ b/source/model-data/indexes.txt @@ -202,9 +202,44 @@ Advanced Index Configuration This section shows how to create the following advanced index types: +- :ref:`django-indexes-atlas-search` - :ref:`django-indexes-partial` - :ref:`django-indexes-unique` +.. _django-indexes-atlas-search: + +Atlas Search Indexes +~~~~~~~~~~~~~~~~~~~~ + +Atlas Search indexes specify the behavior of an Atlas Search, which is a +full-text search on collections hosted on MongoDB Atlas. + +To create an Atlas Search index, assign the ``indexes`` option in your model's +``Meta`` class to a ``SearchIndex`` object. Pass the following arguments to the +``SearchIndex()`` constructor: + +- ``fields``: The fields you want to index. +- ``name``: *(Optional)* The name of your Atlas Search index. If you do not + specify this argument, {+framework+} automatically generates an index name. + +The following example updates the ``Recipe`` model's ``Meta`` class to create +an Atlas Search index named ``"title_search_idx"`` on the ``title`` field: + +.. literalinclude:: /includes/model-data/indexes.py + :start-after: start-atlas-search + :end-before: end-atlas-search + :language: python + :copyable: + :emphasize-lines: 3-8 + +.. tip:: + + To learn more about Atlas Search queries and indexes, see the following resources: + + - :atlas:`Atlas Search ` in the Atlas documentation. + - `SearchIndex <{+api+}ref/models/indexes/#searchindex>`__ class in the + {+django-odm+} API documentation. + .. _django-indexes-partial: Partial Indexes