How to call solr to optimize using java code
Not under shell I开发者_运维百科 want to call the optimize using Java code and get notification when the optimize process is finished.
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'
Using solrj, you call the optimize method of the class CommonsHttpSolrServer.
See this question about how to know when the optimize is done.
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
精彩评论