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 Saikat Kanjilal <sx...@hotmail.com> on 2013/06/04 18:41:12 UTC

Creating a new core programmicatically in solr

Hello everyone,
I have written some simple java code to create a core programmatically in solr and it seems to be returning 200 but I see no core being created inside the solr admin console, here's what I've tried, BTW for what its worth we are using the DSE implementation of solr which uses cassandra underneath:

1) The code to create the core is shown below:

HttpGet req = new HttpGet(getSolrClient().getBaseUrl()+ADMIN_CORE_CONSTRUCT+"?action="+action+"&name="+name);

ADMIN_CORE_CONSTRUCT=/admin/cores

Result When executing this code:  200 but no core created, note that in the previous parts of the code I have successfully created the solrconfig.xml and schema.xml successfully for this core using the appropriate rest APIs

2) From the command line if I type:
curl "http://hostname:8983/solr/admin/cores?action=CREATE&name=NEW_SCHEMA.solr"

The core will get created successfully and I will see it in the solr admin console, for some reason the double quotes are needed for this command


3) From the browser using restclient I tried to emulate the curl behavior by typing in the URL and making it a GET request with the appropriate headers: (Accept:application/xml;charset=UTF-8
Content-Type:application/xml;charset=UTF-8), however I keep getting BadRequest responses from the DSE solr cluster.


I cant see anything obvious that number 3 and number 1 are missing, I was wondering if anyone had run into this before and what the issue may be.  Thanks for your help.

Regards



 		 	   		  

RE: Creating a new core programmicatically in solr

Posted by Saikat Kanjilal <sx...@hotmail.com>.
Thanks, good catch, completely forgot about the & and its meaning in unix.

> From: jack@basetechnology.com
> To: solr-user@lucene.apache.org
> Subject: Re: Creating a new core programmicatically in solr
> Date: Tue, 4 Jun 2013 13:22:34 -0400
> 
> The double quotes are required for curl simply because of the "&", which 
> tells the shell to run the preceding command in the background. The quotes 
> around the full URL escape the "&".
> 
> -- Jack Krupansky
> 
> -----Original Message----- 
> From: Saikat Kanjilal
> Sent: Tuesday, June 04, 2013 12:56 PM
> To: solr-user@lucene.apache.org
> Subject: RE: Creating a new core programmicatically in solr
> 
> I'm aware of the CoreAdminRequest API, however given the fact that our solr 
> cluster machines have their own internal configurations I'd prefer to use 
> the http approach rather then having to specify the instanceDir or the 
> solrServer.    One issue I was thinking of was the double quotes needed 
> around the curl command and how to simulate that through the restclient or 
> even the java code, its weird that this is needed.  Anyways thanks for the 
> inputs.
> 
> > Date: Tue, 4 Jun 2013 09:52:03 -0700
> > From: bbarani@gmail.com
> > To: solr-user@lucene.apache.org
> > Subject: Re: Creating a new core programmicatically in solr
> >
> > I would use the below method to create new core on the fly...
> >
> > CoreAdminResponse e = CoreAdminRequest.createCore("name", "instanceDir",
> > server);
> >
> > http://lucene.apache.org/solr/4_3_0/solr-solrj/org/apache/solr/client/solrj/response/CoreAdminResponse.html
> >
> >
> >
> >
> > --
> > View this message in context: 
> > http://lucene.472066.n3.nabble.com/Creating-a-new-core-programmicatically-in-solr-tp4068132p4068134.html
> > Sent from the Solr - User mailing list archive at Nabble.com.
>  
> 
 		 	   		  

Re: Creating a new core programmicatically in solr

Posted by Jack Krupansky <ja...@basetechnology.com>.
The double quotes are required for curl simply because of the "&", which 
tells the shell to run the preceding command in the background. The quotes 
around the full URL escape the "&".

-- Jack Krupansky

-----Original Message----- 
From: Saikat Kanjilal
Sent: Tuesday, June 04, 2013 12:56 PM
To: solr-user@lucene.apache.org
Subject: RE: Creating a new core programmicatically in solr

I'm aware of the CoreAdminRequest API, however given the fact that our solr 
cluster machines have their own internal configurations I'd prefer to use 
the http approach rather then having to specify the instanceDir or the 
solrServer.    One issue I was thinking of was the double quotes needed 
around the curl command and how to simulate that through the restclient or 
even the java code, its weird that this is needed.  Anyways thanks for the 
inputs.

> Date: Tue, 4 Jun 2013 09:52:03 -0700
> From: bbarani@gmail.com
> To: solr-user@lucene.apache.org
> Subject: Re: Creating a new core programmicatically in solr
>
> I would use the below method to create new core on the fly...
>
> CoreAdminResponse e = CoreAdminRequest.createCore("name", "instanceDir",
> server);
>
> http://lucene.apache.org/solr/4_3_0/solr-solrj/org/apache/solr/client/solrj/response/CoreAdminResponse.html
>
>
>
>
> --
> View this message in context: 
> http://lucene.472066.n3.nabble.com/Creating-a-new-core-programmicatically-in-solr-tp4068132p4068134.html
> Sent from the Solr - User mailing list archive at Nabble.com.
 


RE: Creating a new core programmicatically in solr

Posted by Saikat Kanjilal <sx...@hotmail.com>.
I need to simulate this curl command line with java code:

curl "http://10.42.6.74:8983/solr/admin/cores?action=CREATE&name=NEW_SCHEMA.solr"

Obviously doing a simple HttpGet with the appropriate query parameters is not the answer. I dont believe your example is not going to work because I am passing in a string already into the constructor for the HttpGet class (namely getSolrClient().getBaseUrl()+ADMIN_CORE_CONSTRUCT+"?action="+action+"&name="+name), adding quotes around it will confuse the compiler.   Let me know if I missed something here.

> Date: Tue, 4 Jun 2013 10:03:50 -0700
> From: bbarani@gmail.com
> To: solr-user@lucene.apache.org
> Subject: RE: Creating a new core programmicatically in solr
> 
> did you try escaping double quotes when you are making the http request.
> 
> HttpGet req = new
> HttpGet(\"+getSolrClient().getBaseUrl()+ADMIN_CORE_CONSTRUCT+"?action="+action+"&name="+name+\"); 
> 
> HttpResponse response = client.execute(request);
> 
> 
> 
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Creating-a-new-core-programmicatically-in-solr-tp4068132p4068139.html
> Sent from the Solr - User mailing list archive at Nabble.com.
 		 	   		  

RE: Creating a new core programmicatically in solr

Posted by bbarani <bb...@gmail.com>.
did you try escaping double quotes when you are making the http request.

HttpGet req = new
HttpGet(\"+getSolrClient().getBaseUrl()+ADMIN_CORE_CONSTRUCT+"?action="+action+"&name="+name+\"); 

HttpResponse response = client.execute(request);



--
View this message in context: http://lucene.472066.n3.nabble.com/Creating-a-new-core-programmicatically-in-solr-tp4068132p4068139.html
Sent from the Solr - User mailing list archive at Nabble.com.

RE: Creating a new core programmicatically in solr

Posted by Saikat Kanjilal <sx...@hotmail.com>.
I'm aware of the CoreAdminRequest API, however given the fact that our solr cluster machines have their own internal configurations I'd prefer to use the http approach rather then having to specify the instanceDir or the solrServer.    One issue I was thinking of was the double quotes needed around the curl command and how to simulate that through the restclient or even the java code, its weird that this is needed.  Anyways thanks for the inputs.

> Date: Tue, 4 Jun 2013 09:52:03 -0700
> From: bbarani@gmail.com
> To: solr-user@lucene.apache.org
> Subject: Re: Creating a new core programmicatically in solr
> 
> I would use the below method to create new core on the fly...
> 
> CoreAdminResponse e = CoreAdminRequest.createCore("name", "instanceDir",
> server);
> 
> http://lucene.apache.org/solr/4_3_0/solr-solrj/org/apache/solr/client/solrj/response/CoreAdminResponse.html
> 
> 
> 
> 
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Creating-a-new-core-programmicatically-in-solr-tp4068132p4068134.html
> Sent from the Solr - User mailing list archive at Nabble.com.
 		 	   		  

Re: Creating a new core programmicatically in solr

Posted by bbarani <bb...@gmail.com>.
I would use the below method to create new core on the fly...

CoreAdminResponse e = CoreAdminRequest.createCore("name", "instanceDir",
server);

http://lucene.apache.org/solr/4_3_0/solr-solrj/org/apache/solr/client/solrj/response/CoreAdminResponse.html




--
View this message in context: http://lucene.472066.n3.nabble.com/Creating-a-new-core-programmicatically-in-solr-tp4068132p4068134.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Creating a new core programmicatically in solr

Posted by Jack Krupansky <ja...@basetechnology.com>.
Best to submit your inquiry as a DataStax support ticket or on their support 
forum. They have people standing by ready to support you.

-- Jack Krupansky

-----Original Message----- 
From: Saikat Kanjilal
Sent: Tuesday, June 04, 2013 12:41 PM
To: solr-user@lucene.apache.org
Subject: Creating a new core programmicatically in solr

Hello everyone,
I have written some simple java code to create a core programmatically in 
solr and it seems to be returning 200 but I see no core being created inside 
the solr admin console, here's what I've tried, BTW for what its worth we 
are using the DSE implementation of solr which uses cassandra underneath:

1) The code to create the core is shown below:

HttpGet req = new 
HttpGet(getSolrClient().getBaseUrl()+ADMIN_CORE_CONSTRUCT+"?action="+action+"&name="+name);

ADMIN_CORE_CONSTRUCT=/admin/cores

Result When executing this code:  200 but no core created, note that in the 
previous parts of the code I have successfully created the solrconfig.xml 
and schema.xml successfully for this core using the appropriate rest APIs

2) From the command line if I type:
curl 
"http://hostname:8983/solr/admin/cores?action=CREATE&name=NEW_SCHEMA.solr"

The core will get created successfully and I will see it in the solr admin 
console, for some reason the double quotes are needed for this command


3) From the browser using restclient I tried to emulate the curl behavior by 
typing in the URL and making it a GET request with the appropriate headers: 
(Accept:application/xml;charset=UTF-8
Content-Type:application/xml;charset=UTF-8), however I keep getting 
BadRequest responses from the DSE solr cluster.


I cant see anything obvious that number 3 and number 1 are missing, I was 
wondering if anyone had run into this before and what the issue may be. 
Thanks for your help.

Regards