3

I am using SolrJ for indexing my data. I am updating the Synonym.txt file dynamically but Solr server is not getting the latest changes from Synonym.txt file, my previous question is how to update synonym.txt file dynamically? So I have to reload/restart the Solr core programatically... so how can I do that...?

thanks in advance...

Community
  • 1
  • 1
milind_db
  • 1,274
  • 5
  • 34
  • 56

2 Answers2

9

The following code should be what you're looking for:

CoreAdminRequest adminRequest = new CoreAdminRequest();
adminRequest.setAction(CoreAdminAction.RELOAD);
CoreAdminResponse adminResponse = adminRequest.process(new HttpSolrServer(solrUrl));
NamedList<NamedList<Object>> coreStatus = adminResponse.getCoreStatus();
javanna
  • 59,145
  • 14
  • 144
  • 125
  • thanks for your reply @javanna...can you please tell me what adminResponse.getCoreStatus(); returns? I am getting coreStatus as 'null' ... – milind_db Jul 20 '12 at 12:39
  • It should return the content of the status element within the response...are you sure the solrUrl is correct? – javanna Jul 20 '12 at 12:42
  • yes,I am doing indexing and searching using the SolrServer using same url,which is working fine... – milind_db Jul 20 '12 at 12:46
  • I see, but if you are working with a multicore Solr you are indexing on a specific core, while the coreadmin is not within each core. The url you have to provide is without the core name. – javanna Jul 20 '12 at 12:54
  • Ok, the url is correct. Have you enabled the [core admin interface](http://wiki.apache.org/solr/CoreAdmin)? Can you reach it from your browser? http://localhost:8983/solr/cores?action=RELOAD&core=corename – javanna Jul 20 '12 at 13:03
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/14209/discussion-between-milind-ensarm-and-javanna) – milind_db Jul 21 '12 at 04:37
1

SolrJ contains a static convenience method for that in CoreAdminRequest class:

reloadCore("<YOUR_CORE_NAME>", solrClient)
heldev
  • 846
  • 7
  • 9