How to dynamically loading data for solr ?

Our application will often face all kinds of demand.  Among the them , the most taboo is to the restart the server.  In the application of some large, restart the service  may bring some serious impact. 

So, in most of the time. we should try to avoid to restart .

Then , In Solr ,how should we dynamic load some data ? such as : The dynamic load our index or  Dynamic update our modified schemal and solrconfig.xml.

if you need, the CoreAdminRequest class is a good  choice.

Example Code is given blow :


/**
	 * dynamic adding indexes
	 * 
	 * Search technology group :  324714439
	 * 
	 * 
	 * */
	public static void reloadIndex()throws Exception{
		CoreAdminRequest admin=new CoreAdminRequest();
		//some index need to be added
		String []indexDirs={"D:\\mysolr\\webapps\\solr\\solr_home\\collections\\collection1\\data\\index"};
		// String []srcCores={"collection2","collection1"};
		 String []srcCores={};		 
		 server.setBaseURL("http://localhost:9001/solr/collection2");
		 server.deleteByQuery("*:*");//clear old index
		 server.setBaseURL("http://localhost:9001/solr/");
	 	 admin.mergeIndexes("collection2", indexDirs, srcCores, server);//copy new index into target
	  	 admin.reloadCore("collection2", server);
	  	server.setBaseURL("http://localhost:9001/solr/collection2");
	 	 server.commit();
		
		System.out.println("execute successful !");
		
	}


/*
	 * Dynamic update SolrCore
	 * 
	 * avoid to the restart service
	 * 
	 * **/
	public static void reloadCore()throws Exception{
		
		HttpSolrServer s=new HttpSolrServer("http://localhost:9003/solr");
		CoreAdminRequest core=new CoreAdminRequest();
		core.reloadCore("collection1", s);
		System.out.println("reload success!");
		s.commit();
		
	}


Some is marked on the images below part, can be easy dynamically loaded .



	/**
	 * Method 2
	 * 
	 * some new method
	 * you don't reload core again .
	 * 
	 * **/
public static void reloadIndex3()throws Exception{
		  HttpSolrServer server=new HttpSolrServer("http://localhost:9004/solr/collection2");
				
				CoreAdminRequest admin=new CoreAdminRequest();
				//some index need to be added
				String []indexDirs={"C:\\Users\\qindongliang\\Desktop\\test\\mysolr\\webapps\\solr\\solr_home\\collections\\collection1\\data\\index"};
				 String []srcCores={};		 
			    server.deleteByQuery("*:*");//clear old index
			 	admin.mergeIndexes("collection2", indexDirs, srcCores, new HttpSolrServer("http://localhost:9004/solr"));//copy new index into target
			  	server.commit();
				System.out.println("execute successful !");	
			}


Restart the service is bad , You need dynamic loading !

你可能感兴趣的:(dynamic,Solr,load)