tags:

views:

48

answers:

3

Not under shell I want to call the optimize use Java code and get returned when the optimize process is finished.

A: 

Just fire a request to /solr/update?optimize=true from anywhere/anything that has access to the Solr server, e.g:

curl 'http://localhost:8983/solr/update?optimize=true'
Mauricio Scheffer
+1  A: 

Using solrj, you call the optimize method of the class CommonsHttpSolrServer.

See this question about how to know when the optimize is done.

Pascal Dimassimo
A: 

Can you be little more specific about your requirement,anyway Here is how i optimize the solr using solrj EmbeddedSolrServer,

SolrServer server = CacheServer.getCacheInstance().getServer();
    try {
        server.optimize();
    } catch (SolrServerException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();

    }

For more details about optimize

Natsabari