久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

solrcloud和solr在集群中建立索方法是什么

172次閱讀
沒有評論

共計 2833 個字符,預計需要花費 8 分鐘才能閱讀完成。

本篇內容介紹了“solrcloud 和 solr 在集群中建立索方法是什么”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓丸趣 TV 小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

1 通過通過 zookeeper 通道建立索引

public static void main(String[] args) throws IOException, SolrServerException {
 // 注意,zkHost 在 windows 偽分布式與 hadoop 分布式設置不一樣
 //windows 偽分布式 zkHost 最后不需要加 /solr,linux 的 hadoop 中需要添加 /solr 
 String zkHost =  node1:2181,node2:2181,node3:2181/solr 
 String defaultCollection =  collection1 
 CloudSolrServer server = new CloudSolrServer(zkHost);
 server.setDefaultCollection(defaultCollection);  
 for (int i = 0; i   1000; ++i) {SolrInputDocument doc = new SolrInputDocument();
 doc.addField( cat ,  book 
 doc.addField(id ,  book-  + i);
 doc.addField(name ,  The Legend of Po part   + i);
 server.add(doc);
 if (i % 100 == 0)
 server.commit(); // periodically flush
 server.commit();}

2  注意,CDH 中,可以看 zookeeper 的設置,最大鏈接數為 60,所以對于 zookeeper 一般用單例

public class myCloudSolrServer {
 // solrServer
 public static CloudSolrServer solrServer;
 
 // 效率不高的方法
// public static synchronized CloudSolrServer getSolrServer() {// if (solrServer == null) {
// try {
// solrServer = new CloudSolrServer(Const.ZK_HOST +  /solr 
// final int zkClientTimeout = 20000; //  心跳 20 秒
// final int zkConnectTimeout = 10000; //  設置鏈接主機超時(單位毫秒)// solrServer.setDefaultCollection(Const.defaultCollection);
// solrServer.setZkClientTimeout(zkClientTimeout);
// solrServer.setZkConnectTimeout(zkConnectTimeout);
// } catch (Exception e) {// e.printStackTrace();
// }
// }
// return solrServer;
// }
 // 支持大并發方法
 public static CloudSolrServer getSolrServer() { if (solrServer == null) { synchronized (myCloudSolrServer.class) { if (solrServer == null) {
 try {
 solrServer = new CloudSolrServer(Const.ZK_HOST +  /solr 
 final int zkClientTimeout = 20000; //  心跳 20 秒
 final int zkConnectTimeout = 10000; //  設置鏈接主機超時(單位毫秒) solrServer.setDefaultCollection(Const.defaultCollection);
 solrServer.setZkClientTimeout(zkClientTimeout);
 solrServer.setZkConnectTimeout(zkConnectTimeout);
 } catch (Exception e) { e.printStackTrace();
 }
 }
 }
 }
 return solrServer;
 }
}

3  急群中可以指定到某個分片

public static void main(String[] args) throws IOException, SolrServerException {
 String url=  node1:8983/solr/core_shard1_replica1 
 String defaultCollection =  collection1 
 HttpSolrServer server = new HttpSolrServer (url); 
 server.setDefaultCollection(defaultCollection);  
 for (int i = 0; i   1000; ++i) {SolrInputDocument doc = new SolrInputDocument();
 doc.addField( cat ,  book 
 doc.addField(id ,  book-  + i);
 doc.addField(name ,  The Legend of Po part   + i);
 server.add(doc);
 if (i % 100 == 0)
 server.commit(); // periodically flush
 server.commit();}

  注意,在建立索引的時候,不要每一個就去 commit,為了提高效率,一般用

 Collection SolrInputDocument  docs = new ArrayList SolrInputDocument 
 for(){ SolrInputDocument doc = new SolrInputDocument(); 
 docs.add(doc);
 }
 server.add(docs);
 server.commit();

  其實 server.commit() 效率也不高,一般用軟提交

“solrcloud 和 solr 在集群中建立索方法是什么”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注丸趣 TV 網站,丸趣 TV 小編將為大家輸出更多高質量的實用文章!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-08-16發表,共計2833字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 宜昌市| 长汀县| 长沙县| 布拖县| 霸州市| 民丰县| 六枝特区| 和平区| 高雄县| 临武县| 江山市| 大洼县| 六枝特区| 灯塔市| 昭通市| 新宾| 呼和浩特市| 漠河县| 达州市| 环江| 虎林市| 明水县| 开原市| 额济纳旗| 慈溪市| 信丰县| 新泰市| 荥阳市| 南通市| 涞源县| 柳林县| 焉耆| 石林| 天峨县| 临清市| 卓尼县| 陆良县| 中阳县| 铜梁县| 正蓝旗| 广东省|