solrcloud

 

 1 @Test

 2     public void querySolrCloud(){

 3         String zkHost = "127.0.0.1:2181";

 4         String defaultCollection = "test";

 5         try {

 6             CloudSolrServer cloudServer = new CloudSolrServer(zkHost);

 7             cloudServer.setDefaultCollection(defaultCollection);

 8             ModifiableSolrParams params = new ModifiableSolrParams();

 9             params.set("q", "*:*");

10             params.set("start", "0");

11             QueryResponse response = cloudServer.query(params);

12             SolrDocumentList results = response.getResults();

13             for(int i=0; i<results.size(); i++){

14                 System.out.println(results.get(i));

15             }

16         } catch (MalformedURLException e) {

17             // TODO Auto-generated catch block

18             e.printStackTrace();

19         } catch (SolrServerException e) {

20             // TODO Auto-generated catch block

21             e.printStackTrace();

22         }

23     }
View Code

 

 

如下,出现 类似 Exception in thread "main" org.apache.solr.common.SolrException: Unknown document router '{name=compositeId}' 异常时,一般是java客户客户版本不一致导致的错误

 

 1 Exception in thread "main" org.apache.solr.common.SolrException: Unknown document router '{name=compositeId}'

 2     at org.apache.solr.common.cloud.DocRouter.getDocRouter(DocRouter.java:46)

 3     at org.apache.solr.common.cloud.ClusterState.collectionFromObjects(ClusterState.java:242)

 4     at org.apache.solr.common.cloud.ClusterState.load(ClusterState.java:219)

 5     at org.apache.solr.common.cloud.ClusterState.load(ClusterState.java:195)

 6     at org.apache.solr.common.cloud.ZkStateReader.createClusterStateWatchersAndUpdate(ZkStateReader.java:286)

 7     at org.apache.solr.client.solrj.impl.CloudSolrServer.connect(CloudSolrServer.java:144)

 8     at org.apache.solr.client.solrj.impl.CloudSolrServer.request(CloudSolrServer.java:168)

 9     at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:90)

10     at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:301)

11     at com.teshehui.SolrTest.main(SolrTest.java:69)
View Code

 

你可能感兴趣的:(solrCloud)