简体   繁体   English

Elasticsearch无法使用liquibase加载的数据

[英]Elasticsearch not working with data loaded by liquibase

I have a project that was generated by JHipster 3.0.0 and I'm using elasticsearch as search engine. 我有一个由JHipster 3.0.0生成的项目,并且正在使用elasticsearch作为搜索引擎。

I'm loading data into one table using liquibase but I can't query those data using elasticsearch because I never called the save() method on the DataSearchRepository with the data loaded by liquibase. 我正在使用liquibase将数据加载到一个表中,但是我无法使用elasticsearch查询这些数据,因为我从未使用由liquibase加载的数据调用DataSearchRepository上的save()方法。

This is how I'm loading the data in a liquibase xml file : 这就是我将数据加载到liquibase xml文件中的方式:

    <sqlFile dbms="postgresql"
             encoding="utf8"
             path="../data.sql"
             relativeToChangelogFile="true"/>

For now, I load all the data and then save them using the DataSearchRepository when the application starts : 现在,我加载所有数据,然后在应用程序启动时使用DataSearchRepository保存它们:

@PostConstruct
private void init() {
   dataSearchRepository.save(dataRepository.findAll());
}

But I would like to do it only one time, not every time the application start. 但是我只想执行一次,而不是每次应用程序启动时都这样做。

Those data are "static" (30 000 rows) so that's why I would like to keep using the sql file for loading them. 这些数据是“静态的”(3万行),所以这就是为什么我想继续使用sql文件加载它们的原因。

Is there a better way of doing that or I have to stick with my way ? 有更好的方法做到这一点,还是我必须坚持下去?

Regards 问候

Try my project here: https://github.com/geraldhumphries/generator-jhipster-elasticsearch-reindexer 在这里尝试我的项目: https : //github.com/geraldhumphries/generator-jhipster-elasticsearch-reindexer

This generates a service that allows you to sync Elasticsearch with your database. 这将生成一项服务,使您可以将Elasticsearch与数据库同步。 It's very similar to your implementation but it needs to be run manually by an admin user and is accessible through your API. 它与您的实现非常相似,但是需要由管理员用户手动运行,并且可以通过您的API进行访问。 In your case, you just need to run it once manually while your application is running and it will index the 30,000 rows you inserted using Liquibase. 对于您的情况,您只需要在应用程序运行时手动运行一次,它将为您使用Liquibase插入的30,000行编制索引。

You can modify the generated service to remove indexing for every other entity. 您可以修改生成的服务以删除所有其他实体的索引。 There is a planned feature to allow you to ignore certain entities. 有一项计划的功能,可让您忽略某些实体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM