You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by vidya <vi...@tcs.com> on 2016/02/10 14:55:08 UTC

Solrj-collection creation

Hi
 
  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?


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.

Anyone can help me.
Thanks in advance



--
View this message in context: http://lucene.472066.n3.nabble.com/Solrj-collection-creation-tp4256380.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Solrj-collection creation

Posted by Erick Erickson <er...@gmail.com>.
Since you're using SolrJ anyway just use the
CollectionsAdminRequest. You can see
examples of it's use in the test cases, take a look
at CollectionsApiSolrJTests..

Best,
Erick

On Wed, Feb 10, 2016 at 5:55 AM, vidya <vi...@tcs.com> wrote:
> Hi
>
>   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?
>
>
> 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.
>
> Anyone can help me.
> Thanks in advance
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Solrj-collection-creation-tp4256380.html
> Sent from the Solr - User mailing list archive at Nabble.com.

RE: Solrj-collection creation

Posted by "Davis, Daniel (NIH/NLM) [C]" <da...@nih.gov>.
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:apache@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


Re: Solrj-collection creation

Posted by Shawn Heisey <ap...@elyograg.org>.
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