@@ -234,16 +234,40 @@ Available Fields
234
234
instance.
235
235
236
236
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
+
237
261
Document id
238
262
===========
239
263
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
241
265
part of the document itself. The default behavior of ``django_elasticsearch_dsl ``
242
266
is to use the primary key of the model as the document's id (``pk `` or ``id ``).
243
267
Nevertheless, it can sometimes be useful to change this default behavior. For this, one
244
268
can redefine the ``generate_id(cls, instance) `` class method of the ``Document `` class.
245
269
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
247
271
article's integer id, one could use:
248
272
249
273
.. code-block :: python
0 commit comments