django - ElasticSearch_ModelFieldNotMappedError

标签 django python-3.x elasticsearch

我正在使用Django Elasticsearch版本6.1.0,目前遇到这种错误:

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

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

这是文档。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']

谁能帮我这个 ?

最佳答案

引起此错误的小数字段。
从字段中删除它,然后执行类似的操作。

  from django_elasticsearch_dsl import DocType, Index,fields


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

      class Meta:
      . . .. . . . . 

关于django - ElasticSearch_ModelFieldNotMappedError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51759969/

相关文章:

python - DRF : how to change the value of the model fields before saving to the database

python - Django:在提交表单时生成唯一的 8 字符字母数字 ID 字符串

python - 模仿 spyder 排序列

python - Kubernetes Python 客户端 : update deployment spec with affinity

grails - 在grails中安装elasticsearch插件时出现NoNodeAvailableException

json - 别名时更新ElasticSearch interval_refresh

python - Django 数据库和线程

python - 缓存查询集

python字典keyError

elasticsearch - 无法远程连接到 Elasticsearch