gpt4 book ai didi

django - ElasticSearch_ModelFieldNotMappedError

转载 作者:行者123 更新时间:2023-12-02 23:18:53 24 4
gpt4 key购买 nike

我正在使用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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com