Ehsan Zaffar
Ehsan Zaffar

Reputation: 33

using CollectionAdminRequest.Create from SolrJ to create a collection

How can I use CollectionAdminRequest.Create in SolrJ to create a new collection in SolrCloud running with zookeeper.

I tried

    public void createIndex(String targetUuid) {
            HttpSolrClient solrClient = new HttpSolrClient.Builder("http://localhost:8983/solr/").build();


            try {
                // 1. Create Index with two shards and one replicas
                if(uploadConfigset()) {
                    //Error Here    
                    CollectionAdminRequest.Create creator = new CollectionAdminRequest.Create(targetUuid,"tg_configset",1,2,0,0);
                    creator.setMaxShardsPerNode(2);
                    creator.process(solrClient);
                }
            } catch (IOException | SolrServerException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

But can not use CollectionAdminRequest.Create as its constructor is 'protected'

Upvotes: 2

Views: 1000

Answers (1)

MatsLindh
MatsLindh

Reputation: 52882

Use one of the CollectionAdminRequest.createCollection methods. You're not supposed to call the constructor directly any longer, as it has been deprecated for the createCollection methods on the CollectionAdminRequest class.

CollectionAdminRequest.Create creator = CollectionAdminRequest.createCollection("newcollection", "tg_configset", 1, 2)

This still returns a CollectionAdminRequest.Create object, so the rest of the code should work as you'd expect.

Upvotes: 3

Related Questions