So let's go back
I have a JHipster project that uses the elasticsearch java client built into spring boot .
I recently made some important changes to the datasets, as we migrated the entire new dataset from different repositories
When you deploy the application, everything works fine, all SearchRepositories load without problems and all search capabilities are smoothed out
Problems arise when starting from a test environment. There were no changes to the application-test.yml , nor to the elasticsearch java configuration file.
We have code that updates indexes, and I run it several times, it seems that it updates clusters indices just fine, but where I suffer in the target folder, it just wonβt create new indexes
There are 12 indexes that I cannot get to the target folder when working in test mode, however only 5 of them fail in their ResourceIntTest due to the error mentioned in the header
I donβt want to fill this post with hundreds of irrelevant lines of code, so for now, just turn on the workaround, which helps test the failure:
If in initTest from 5 unsuccessful test cases, if I write the following line (obviously, changing the class name in each case):
surveyDataQualitySearchRepository.save(surveyDataQualityRepository.findAll());
Then the index will be created by itself, and the test file will not work, however, this does not have to be done manually, it must be created when the resetIndex method in the IndexReinitializer class IndexReinitializer called during deployment
resetIndex:
@PostConstruct public void resetIndex() { long t = currentTimeMillis(); elasticsearchTemplate.deleteIndex("_all"); t = currentTimeMillis() - t; logger.debug("ElasticSearch indexes reset in {} ms", t); }
Commenting on this piece of code, it also allows you to download all indexes, but it cannot be commented on, since it serves as an index update, plus it works fine in the old version of the application, which still points to the old Data Set
All help would be very welcome, I was on this for almost a full day, trying to understand where the error came from. I am also more than happy to download any code snippets that may be relevant to everyone wanting to help here.
EDIT . To add code to restore indexes as requested through comments
@Test public void synchronizeData() throws Exception{ resetIndex(); activePharmaIngredientSearchRepository.save(activePharmaIngredientRepository.findAll()); countrySearchRepository.save(countryRepository.findAll()); dosageUnitSearchRepository.save(dosageUnitRepository.findAll()); drugCategorySearchRepository.save(drugCategoryRepository.findAll()); drugQualityCategorySearchRepository.save(drugQualityCategoryRepository.findAll()); formulationSearchRepository.save(formulationRepository.findAll()); innDrugSearchRepository.save(innDrugRepository.findAll()); locationSearchRepository.save(locationRepository.findAll()); manufacturerSearchRepository.save(manufacturerRepository.findAll()); outletTypeSearchRepository.save(outletTypeRepository.findAll()); publicationSearchRepository.save(publicationRepository.findAll()); publicationTypeSearchRepository.save(publicationTypeRepository.findAll()); qualityReferenceSearchRepository.save(qualityReferenceRepository.findAll()); reportQualityAssessmentAssaySearchRepository.save(reportQualityAssessmentAssayRepository.findAll());