我正在使用django-弹性搜索-dsl包,并且有点进退两难。这是我的代码:
models.py
class Source(models.model):
name = models.CharField(max_length=50)
class Posting(models.Model):
title = models.CharField(max_length=250)
sources = models.ManyToMany(Sources, related_name="postings", through="PostingSource")
class PostingSource(models.Model):
posting = models.ForeignKey(Posting, related_name="posting_sources", on_delete=models.CASCADE)
source = models.ForeignKey(Source, related_name="posting_sources", on_delete=models.CASCADE)
documents.py
class PostingDocument(Document):
sources = fields.ObjectField(properties={"name": fields.KeywordField()})
class Index:
name = "posting"
settings = {"all the settings stuff"}
class Django:
model = Posting
fields = ["title"]
related_models = [PostingSource]
def get_queryset(self):
return super().get_queryset().select_related("sources")
def get_instance_from_related(self, related_instance):
if isinstance(related_instance, PostingSource):
return related_instance.posting
我的问题是,当我更新帖子上的来源时,由于某种原因,弹性搜索索引pre_save更新,而不是post_save。我基本上必须使用相同的来源进行2次放置请求,以使更改反映在我的索引中。我在文档中添加了 一个,它似乎可以正常工作,但感觉它以后会导致性能问题。任何帮助或指导将不胜感激。def prepare_sources(self, instance):
30秒到达战场
相关分类