【问题标题】:Rebuild_index does not update new items Haystack Elasticsearch DjangoRebuild_index 不更新新项目 Haystack Elasticsearch Django
【发布时间】:2018-04-24 21:36:39
【问题描述】:

一直在寻找此解决方案,但找不到任何东西。我刚刚开始使用 Haystack == 2.6.1,并且正在使用 Elasticsearch==2.4.1 和 Elasticsearch server 2.4.6。在关注 haystack 的 getting started 之后,我能够执行搜索并获得结果。跑完之后

python manage.py rebuild_index

它第一次起作用,因为就像我说的那样,我能够执行搜索。但后来我在我的数据库中添加了 3 个条目并尝试重建和/或更新索引。但现在我看到了:

RuntimeWarning: DateTimeField Order.dateEntered received a naive datetime (2017-11-11 16:07:54.324473) while time zone support is active.
  RuntimeWarning)
Indexing 32 orders
GET /haystack/_mapping [status:404 request:0.004s]

所以当我搜索时,我仍然看不到我的新条目。我现在有 35 个订单(它只索引了 32 个),我看到了 GET /haystack/_mapping 的 404 响应。 抱歉,我是新手,所以有些问题可能看起来很愚蠢:

  1. haystack 期望得到什么;我有一个为 elasticsearch 运行的本地服务器,但也应该有一个 haystack 服务器?
  2. haystack 是否会因为幼稚的日期时间警告而无法索引新项目?
  3. 每次向数据库添加新项目时,是否必须重新启动 elasticsearch 服务器?

更新:早上我重新启动了 elasticsearch 服务器并重新运行python manage.py rebuild_index,然后它在索引过程中捕获了所有 35 个!但是我尝试再次添加一个条目并重新运行它,它仍然只索引 35 个项目 - 现在我有 36 个,所以它应该索引 36 个项目。

【问题讨论】:

    标签: python django elasticsearch django-haystack


    【解决方案1】:

    事实证明:

    RuntimeWarning: DateTimeField Order.dateEntered received a naive datetime (2017-11-11 16:07:54.324473) while time zone support is active.
      RuntimeWarning)
    

    是问题所在。在search_index.py 中,它基于index_queryset 函数进行更新。在“入门”文档中,index_queryset 应如下所示:

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(pub_date__lte=datetime.datetime.now())
    

    但由于 pub_date 不是正确的时区,或者因为它是一种幼稚的格式,rebuild_index 没有提取最新的项目。所以我使用了 django.utils 时区日期:

    from django.utils import timezone
    
    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(pub_date__lte=timezone.now())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 2013-01-07
      • 1970-01-01
      • 2012-11-28
      相关资源
      最近更新 更多