简体   繁体   中英

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.

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.

This is how I'm loading the data in a liquibase xml file :

    <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 :

@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.

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

This generates a service that allows you to sync Elasticsearch with your database. It's very similar to your implementation but it needs to be run manually by an admin user and is accessible through your 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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