Ananth
Ananth

Reputation: 157

SOLR configuration for Multiple Environments

I am new to SOLR but I have setup the SOLR Cloud and have setup a core "participant_dev". We have multiple environments namely., CI,Dev,QA,UAT and Prod.

For the single core, the configuration is simple enough. In the Spring Boot application yaml add the solr server url like so

spring:
  data:
    solr:
      host: server url

The solr Document is annotated with

@SolrDocument(solrCoreName = "participant_dev")
public class Solr Participant{

     ....
}

This works but now the requirement is as the application moves to different environments I have to setup solr cores like 'participant_ci','participant_qa','participant_uat' and such. Can you advise as to how to change the solr core name based on the environment. So that, In CI,

@SolrDocument(solrCoreName = "participant_ci")
public class Solr Participant{

     ....
}

In QA,

@SolrDocument(solrCoreName = "participant_qa")
public class Solr Participant{

     ....
}

Upvotes: 0

Views: 782

Answers (1)

user1211
user1211

Reputation: 1515

You can set by creating solr client bean in Application class and removing @SolrDocument annotation. So the default collection would be as specified.

@Bean
    public SolrClient solrClient()
    {
        CloudSolrClient client = new CloudSolrClient(env.getRequiredProperty("spring.data.solr.zk-host"));
        client.setDefaultCollection("participant_"+env.getActiveProfiles()[0]);
        return client;
    }

The other option would be by creating custom repository, but that would add lot of unwanted code.

Upvotes: 1

Related Questions