Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
    }
like image 997
Steven Avatar asked May 16 '17 14:05

Steven


People also ask

What is index in Elasticsearch?

An index is defined as: An index is like a 'database' in a relational database. It has a mapping which defines multiple types. An index is a logical namespace which maps to one or more primary shards and can have zero or more replica shards.

What is elastic search?

Elasticsearch is a distributed search and analytics engine built on Apache Lucene. Since its release in 2010, Elasticsearch has quickly become the most popular search engine and is commonly used for log analytics, full-text search, security intelligence, business analytics, and operational intelligence use cases.


1 Answers

Please try to update to the latest version of spring-data-elasticsearch

like image 85
ignacio.suay Avatar answered Oct 22 '22 16:10

ignacio.suay