django-elasticsearch-dsl icon indicating copy to clipboard operation
django-elasticsearch-dsl copied to clipboard

ModelFieldNotMappedError

Open mhasan09 opened this issue 6 years ago • 3 comments

django_elasticsearch_dsl.exceptions.ModelFieldNotMappedError: Cannot convert model field price to an Elasticsearch field!

Currently I'm getting this kind of error Elasticsearch version : 6.1.0

Here's my documents.py

from django_elasticsearch_dsl import DocType, Index from crudapp.models import Product product=Index('products') @product.doc_type class ProductDocument(DocType): class Meta: model = Product fields = ['description', 'price', 'quantity']

mhasan09 avatar Aug 06 '18 09:08 mhasan09

having same issue, any luck?

dastiv21 avatar May 16 '19 18:05 dastiv21

class ProductDocument(DocType):
    # set here fields Price Model you wanna use
    price = NestedField(properties={
        'value': fields.FloatField(),
        'id': fields.IndegerField()
    })

    class Meta:
        model = Product
        related_model = [PriceModel]
        fields = ['description', 'quantity']

mykytiakv avatar May 15 '20 10:05 mykytiakv

You can also provide your own prepare__price(self, obj) method.

alexgarel avatar May 15 '20 11:05 alexgarel