Mahabubul Hasan
Mahabubul Hasan

Reputation: 71

ElasticSearch_ModelFieldNotMappedError

I'm using Django Elasticsearch version 6.1.0 and currently I'm getting this kind of error:

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

Here is my models.py

class Product(models.Model):
    description = models.CharField(max_length=100)
    price = models.DecimalField(max_digits=9, decimal_places=2)
    quantity = models.IntegerField()

and here's the 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']

Can anyone help me with this ?

Upvotes: 1

Views: 1016

Answers (1)

DimitrisBovasianos
DimitrisBovasianos

Reputation: 66

The decimal field it is causing this error. delete it from fields, and do something like this.

  from django_elasticsearch_dsl import DocType, Index,fields


  class ProductDocument(DocType):
      price = FloatField(attr=None, **elasticsearch_properties)

      class Meta:
      . . .. . . . . 

Upvotes: 1

Related Questions