@@ -234,16 +234,40 @@ Available Fields
234234instance.
235235
236236
237+ Field Mapping
238+ =============
239+ Django Elasticsearch DSL maps most of the django fields
240+ appropriate Elasticsearch Field. You can find the field
241+ mapping on `documents.py ` file in the `model_field_class_to_field_class `
242+ variable. If you need to change the behavior of this mapping, or add mapping
243+ for your custom field, you can do so by overwriting the classmethod
244+ `get_model_field_class_to_field_class `. Remember, you need to inherit
245+ `django_elasticsearch_dsl.fields.DEDField ` for your custom field.
246+ Like following
247+
248+ .. code-block :: python
249+
250+ from django_elasticsearch_dsl.fields import DEDField
251+
252+ class MyCustomDEDField (DEDField , ElasticsearchField ):
253+ pass
254+
255+ @ classmethod
256+ def get_model_field_class_to_field_class (cls ):
257+ field_mapping = super ().get_model_field_class_to_field_class()
258+ field_mapping[MyCustomDjangoField] = MyCustomDEDField
259+
260+
237261 Document id
238262===========
239263
240- The elasticsearch document id (``_id ``) is not strictly speaking a field, as it is not
264+ The elasticsearch document id (``_id ``) is not strictly speaking a field, as it is not
241265part of the document itself. The default behavior of ``django_elasticsearch_dsl ``
242266is to use the primary key of the model as the document's id (``pk `` or ``id ``).
243267Nevertheless, it can sometimes be useful to change this default behavior. For this, one
244268can redefine the ``generate_id(cls, instance) `` class method of the ``Document `` class.
245269
246- For example, to use an article's slug as the elasticsearch ``_id `` instead of the
270+ For example, to use an article's slug as the elasticsearch ``_id `` instead of the
247271article's integer id, one could use:
248272
249273.. code-block :: python
0 commit comments