Index not Found Exception

So, back again

I have a JHipster generated project which uses an elasticsearch java client embedded in spring boot .

I have recently done some major changes to the datasets since we've been migrating a whole new bunch of data from different repositories

When deploying the application it all works fine, all SearchRepositories are loaded with no problem and all search capabilities roll smooth

The issues come when running from the test environment. There have been no changes what so ever to the application-test.yml file nor to the elasticsearch java config file.

We have some code which updates the indices and I've run it several times, it seems to update the clusters indices just fine, but where I'm suffering is in the target folder, it just won't create the new indices

There are 12 indices that I cannot get in to the target folder when running in test mode, however, only 5 of them fail in their ResourceIntTest because of the error mentioned in the title

I don't want to fill this post with hundreds of irrelevant lines of code, so suffice for now to include the workaround that helps test not to fail:

When in the initTest of the 5 failing test cases, if I write the following line (obviously changing the class name in each different case):

surveyDataQualitySearchRepository.save(surveyDataQualityRepository.findAll());

Then the index will create itself and the testcase will not fail, however this shouldn't be necessary to do manually, it should be created when the resetIndex method in the IndexReinitializer class is called upon deployment

resetIndex:

@PostConstruct
public void resetIndex() {
        long t = currentTimeMillis();
        elasticsearchTemplate.deleteIndex("_all");
        t = currentTimeMillis() - t;
        logger.debug("ElasticSearch indexes reset in {} ms", t);
    }

Commenting this piece of code also allows all indices to be loaded, but it should not be commented as this serves as an updater for the indices, plus it works fine in an old version of the application which is still pointing to the old dataset

All help will be very welcome, I've been on this almost a full day now trying to understand where the error is coming from, I'm also more than happy to upload any pieces of code that may be relevant to anyone willing to help here.

EDIT To add code for the indices rebuild as requested via 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());
        //rqaaQualitySearchRepository.save(rqaaQualityRepository.findAll());
        rqaaTechniqueSearchRepository.save(rqaaTechniqueRepository.findAll());
        samplingTypeSearchRepository.save(samplingTypeRepository.findAll());
        //surveyDataQualitySearchRepository.save(surveyDataQualityRepository.findAll());
        surveyDataSearchRepository.save(surveyDataRepository.findAll());
        techniqueSearchRepository.save(techniqueRepository.findAll());
        tradeDrugApiSearchRepository.save(tradeDrugApiRepository.findAll());
        tradeDrugSearchRepository.save(tradeDrugRepository.findAll());
        publicationDrugTypesSearchRepository.save(publicationDrugTypesRepository.findAll());
        wrongApiSearchRepository.save(wrongApiRepository.findAll());
    }

    private void resetIndex() {
        long t = currentTimeMillis();
        elasticsearchTemplate.deleteIndex("_all");
        t = currentTimeMillis() - t;
        logger.debug("ElasticSearch indexes reset in {} ms", t);
    }

请尝试更新到spring-data-elasticsearch的最新版本

链接地址: http://www.djcxy.com/p/39378.html

上一篇: 带箭头函数语法的Getter

下一篇: 索引未找到例外