Model index reference¶
Some MongoDB-specific indexes, for use on a
model’s Meta.indexes option, are
available in django_mongodb_backend.indexes.
Search indexes¶
MongoDB creates these indexes asynchronously, however, Django’s
AddIndex and
RemoveIndex operations will wait
until the index is created or deleted so that the database state is
consistent in the operations that follow. Adding indexes may take seconds or
minutes, depending on the size of the collection.
Changed in version 5.2.1: The aforementioned waiting was added.
SearchIndex¶
- class SearchIndex(fields=(), field_mappings=None, name=None, analyzer=None, search_analyzer=None)¶
Creates a basic search index on the given field(s).
Some fields such as
DecimalFieldaren’t supported. See the Atlas documentation for a complete list of unsupported data types.Use
field_mappings(instead offields) to create a complex search index.field_mappingsis a dictionary that maps field names to index options. It corresponds todefinition["mappings"]["fields"]in the Static Mapping Example.If
nameisn’t provided, one will be generated automatically. If you need to reference the name in your search query and don’t provide your own name, you can lookup the generated one usingModel._meta.indexes[0].name(substituting the name of your model as well as a different list index if your model has multiple indexes).Use
analyzerandsearch_analyzerto configure the indexing and searching analyzer. If these options aren’t provided, the server defaults tolucene.standard. It corresponds todefinition["analyzer"]anddefinition["searchAnalyzer"]in the Static Mapping Example.Changed in version 5.2.2: The
field_mappings,analyzer, andsearch_analyzerarguments were added.
VectorSearchIndex¶
- class VectorSearchIndex(*, fields=(), name=None, similarities)¶
A subclass of
SearchIndexthat creates a vector search index on the given field(s).The index must reference at least one vector field: an
ArrayFieldwith abase_fieldofFloatFieldorIntegerFieldand asize. It cannot reference anArrayFieldof any other type.It may also have other fields to filter on, provided the field stores
boolean,date,objectId,numeric,string, oruuid.Available values for the required
similaritieskeyword argument are"cosine","dotProduct", and"euclidean"(see About the Similarity Functions for how to choose). You can provide this value either a string, in which case that value will be applied to all vector fields, or a list or tuple of values with a similarity corresponding to each vector field.