异步构建 Hibernate Search 索引以确保不会停机。

Asynchronously build Hibernate Search index to ensure no downtime.

我们正在使用 Hibernate Search(Lucene 引擎)对文本进行模糊搜索 我们存储在 SQL 服务器数据库中并由 Java 中编写的搜索服务使用的一些数据 8. 数据搜索来源是 table,频率适中 edit/update。我们需要的是,对于重建索引时所做的任何更改,我们希望确保搜索功能仍然 运行 并且可以访问,而不是被正在构建的索引过程锁定。

简而言之,如何在构建新索引时临时使用现有索引并在完成时替换它。

不是您问题的答案,但无论如何这对您有帮助:根据我在您的评论中的理解,您实际上不需要完全重建索​​引,您只需要从不同的地方获取更新事件比执行搜索查询的应用程序。

如果您的 "updating" 应用程序使用 Hibernate ORM,您可以在不完全重建索​​引的情况下解决问题:在 "updating" 应用程序中自动增量构建索引(在 [=12 中使用 Hibernate Search) =] 无需进行任何查询),并确保索引可用于 "searching" 应用程序。

后者可以实现:

  • 通过使用实验性 Elasticsearch integration 并将两个应用程序连接到同一个集群:一个将更新它,另一个将使用它进行搜索。
  • 或使用 Lucene 与 filesystem-master/filesystem-slave directory providers, which will allow you to periodically (and without downtime) copy the index from the "updating" application (master) to the "searching" application (slave). Note that if multiple applications update the index, you will need to use the JMS or JGroups backend 的集成,将所有索引更新重定向到主节点并避免冲突。当心,配置 JMS 或 JGroups 不会很明显。