Generally, creating a collection may also include uploading a zookeeper 
configuration:

import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkConfigManager;
import org.apache.solr.common.cloud.ZkStateReader;

/* ... much later ... */

    SolrZkClient zkClient = something.getZkClient();
    ZkConfigManager configManager = new ZkConfigManager(zkClient);
    String confName = something.getConfigName();
    configManager.uploadConfigDir(something.getPath(), confName);

Creating the collection looks like this:

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.response.CollectionAdminResponse;

/* ... later ... */

    CollectionAdminResponse response = new CollectionAdminResponse();
    CollectionAdminRequest.Create request = new CollectionAdminRequest.Create();
    request.setConfigName(something.getConfigName());
    request.setCollectionName(collectionName);
    request.setNumShards(1);                                    // TODO: edit
    request.setReplicationFactor(1);                                    // 
TODO: edit
    response.setResponse(client.request(request));


-----Original Message-----
From: Shawn Heisey [mailto:apa...@elyograg.org] 
Sent: Wednesday, February 10, 2016 11:24 AM
To: solr-user@lucene.apache.org
Subject: Re: Solrj-collection creation

On 2/10/2016 6:55 AM, vidya wrote:
>   I want to connect to solrCloud server from java program using 
> zookeeperHost variable. I know that data can be indexed and searched 
> from a collection using java program. but Can i able to create a 
> collection initially from java program?

Yes.  Use the CloudSolrClient object in the SolrJ API.  It accepts a zkHost 
string.

https://cwiki.apache.org/confluence/display/solr/Using+SolrJ

I'm not sure exactly how to do the collection create, but it will probably 
involve this object:

https://lucene.apache.org/solr/5_4_1/solr-solrj/org/apache/solr/client/solrj/request/CollectionAdminRequest.Create.html

> My problem is that i cannot access solr web page, i'm getting an error 
> like "defected tokens detected". So, i wanted to connect to solr using solrj 
> API.
> For that I need to create a collection initially.Got struck here.

This does not sound like an error generated by Solr.  It must be coming from 
some other aspect of your environment.  Can you get a screenshot or log entry 
showing the problem, place it on the Internet somewhere, and provide a link?

Thanks,
Shawn

Reply via email to