Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method for solrcloud and solr to set up the index in the cluster?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "what is the method of establishing solrcloud and solr in the cluster". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1 indexing through the zookeeper channel

Public static void main (String [] args) throws IOException, SolrServerException {/ / Note: zkHost is different in windows pseudo-distributed and hadoop distributed settings / / windows pseudo-distributed zkHost finally does not need to add "/ solr", linux hadoop needs to add "/ 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 Note: in CDH, you can see the setting of zookeeper. The maximum number of links is 60, so a single example is generally used for zookeeper.

Public class myCloudSolrServer {/ / solrServer public static CloudSolrServer solrServer; / / inefficient method / / public static synchronized CloudSolrServer getSolrServer () {/ / if (solrServer = = null) {/ / try {/ / solrServer = new CloudSolrServer (Const.ZK_HOST + "/ solr"); / / final int zkClientTimeout = 20000; / / heartbeat 20 seconds / / final int zkConnectTimeout = 10000 / / set the linked host timeout (in milliseconds) / solrServer.setDefaultCollection (Const.defaultCollection); / / solrServer.setZkClientTimeout (zkClientTimeout); / / solrServer.setZkConnectTimeout (zkConnectTimeout); / /} catch (Exception e) {/ / e.printStackTrace (); / /} / /} / / return solrServer / / support large concurrency method 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 / / heartbeat 20 seconds final int zkConnectTimeout = 10000; / / set link host timeout (in milliseconds) solrServer.setDefaultCollection (Const.defaultCollection); solrServer.setZkClientTimeout (zkClientTimeout); solrServer.setZkConnectTimeout (zkConnectTimeout) } catch (Exception e) {e.printStackTrace ();} return solrServer;}}

3 A fragment can be specified in the emergency group.

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) server.commit (); / / periodically flush} server.commit ();}

Note that when building an index, do not go to commit every time, in order to improve efficiency, generally use

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

In fact, the efficiency of server.commit () is not high, and soft submission is generally used.

This is the end of the content of "what are the methods of solrcloud and solr in building a cluster". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report