【发布时间】:2021-03-25 19:35:26
【问题描述】:
我有用户模型和评论,我正在使用 django_elasticsearch_dsl 在 ElasticSearch 中建立索引
# models.py
class Comment(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
reply_type = models.JSONField(default=dict)
reply_type内容
reply_type: {
"one": "on... ...",
"two": "tw... ..."
}
索引到弹性我正在这样做
# documents.py
@registry.register_document
class UserDocument(Document):
email = fields.TextField()
username = fields.TextField()
first_name = fields.TextField()
...
...
...
comment = fields.NestedField(properties={
# other fields...
'some_field': fields.TextField(),
'reply_type': fields.ObjectField(),
})
class Index:
name = 'user'
settings = {
'number_of_shards': 1,
'number_of_replicas': 0
}
class Django:
model = User
问题是当我进行索引时,reply_type 是空的
"reply_type": [
{ },
{ }
]
有什么建议吗?
【问题讨论】:
标签: python django elasticsearch django-models