javasolrspring-datasolr4spring-data-solr

Create new SOLR collection at runtime


I am using a SOLR 7.1.0 Server with an JAVA spring boot application. To communicate with the SOLR server I am using "springframework.data.solr" I have a "template" schema from which I want to create new cores at the runtime.

The goal I want to achieve is to create a new core for each customer, while keeping the schema the same.

This is how my SolrConfig looks like:

@Configuration
@EnableSolrRepositories(basePackages = "com.my.repository", multicoreSupport = true)
@ComponentScan
public class SolrConfig {

    @Bean
    public SolrClient solrClient() {
        return new HttpSolrClient("http://localhost:8983/solr");
    }

    @Bean
    @Scope("prototype")
    public SolrTemplate solrTemplate(SolrClient client) throws Exception {
        return new SolrTemplate(client);
    }
}

my repository interface:

public interface OpenItemsDebtorsRepository extends CustomOpenItemsDebtorsRepository, SolrCrudRepository<OpenItemDebtor, String> {
    void setCore(String core);

    @Query("orderNumber:*?0*~")
    List<OpenItemDebtor> findByOrderNumber(String orderNumber);
}

I am looking for something like this:

solrTemplate.CreateNewCore(String coreName)

Do you have any suggestions?


Solution

  • I would strongly suggest to use the native Solr client (SolrJ) for your spring boot project. Have a service component created that would provide you an instance of the the Solr Server (CLoudSolrClient).

    SolrJ has all the components that you would need to create and manage cores and collection.

    I know this is not a straight answer but I hope this helps.