Daily Study Notes (20)

Source: Internet
Author: User

1. There are two methods for SOLR to merge index data. The first method is introduced in version 1.4 and implemented through coreadminhandler. The example is as follows:

Http: // localhost: 8983/SOLR/admin/cores? Action = mergeindexes & core = core0 & indexdir =/opt/SOLR/core1/data/index & indexdir =/opt/SOLR/core2/data/Index


The above command will merge the indexes of core1 and core2 into core0. The most important thing to note here is that once the merge is completed, the commit operation must be called on core0, otherwise, the index data changes are temporarily invisible to searchers and will be visible only when core0 is re-loaded next time.


The implementation code is as follows:

/*** Merge index data ** @ Param otherindexpathlist other index data paths to be merged * @ Param corename name of the target SOLR core to be merged **/private void mergeindexdata (list <string> otherindexpathlist, string corename) {If (null! = Otherindexpathlist & otherindexpathlist. size ()> 0) {httpclient client = new httpclient (); client. setconnectiontimeout (20000); client. setTimeout (20000); client. sethttpconnectionfactorytimeout (20000); stringbuffer sb = new stringbuffer (); For (INT I = 0; I <otherindexpathlist. size (); ++ I) {sb. append ("& indexdir =" + otherindexpathlist. get (I) + "/data/Index");} string mergeindexcmd = "http: //" + constant S. local_address + ":" + this. Port + "/admin/cores? Action = mergeindexes & core = "+ corename; If (sb. length ()> 0) {mergeindexcmd + = sb. tostring ();} httpmethod method = new getmethod (mergeindexcmd); method. getparams (). setcontentcharset ("GBK"); method. getparams (). sethttpelementcharset ("GBK"); method. getparams (). setcredentialcharset ("GBK"); // execute the method. try {If (client.exe cutemethod (method) = 200) {string response = method. getresponsebodyasstring (); If (logger. isinfoenabled () {logger.info ("merge result" + response) ;}} catch (exception e) {logger. error ("failed to merge other index data" + corename + ", index directory:" + otherindexpathlist, e );} // The commit operation takes effect for the merged index on the search. streamingupdatesolrserver httpsolrserver = NULL; httpsolrserver = getsolrserver (constants. local_address, this. port, corename); try {httpsolrserver. commit () ;}catch (exception e ){}}}

The second method is introduced in solr3.3 and is implemented through coreadminhandler. The example is as follows:

Http: // localhost: 8983/SOLR/admin/cores? Action = mergeindexes & core = core0 & srccore = core1 & srccore = core2

The same as the first method, the commit operation must be called on core0 after the merge is completed. Otherwise, the index data changes are temporarily invisible to searchers, it is visible only when core0 is reloaded next time.

The difference between using "srccore" and "indexdir" is as follows:

1) using the "indexdir" parameter, You can merge index data that is not associated with the SOLR core, such as indexes directly created through Lucene.

2) using the "indexdir" parameter, you must note that the index data is not directly written, which means that if it is a SOLR core index, you must disable indexwriter, in this way, a commit command can be triggered.

3) "indexdir" must point to the disk path on the host where the SOLR core is located, which has many restrictions. On the contrary, you can only give srccore the name of a SOLR core, it does not care where the actual index path is.

4) When "srccore" is used, you must ensure that the merged index page will not be damaged even if the source index data has both write operations.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.