IK GitHub address: Https://github.com/medcl/elasticsearch-analysis-ik
Website Description:
How to use the hot update IK participle
Currently the plugin supports hot update ik participle, which is described in the IK configuration file above
<!--the user can configure the remote extension dictionary--
<entry key= "remote_ext_dict" >location</entry>
<!-- Here the user can configure the remote extension Stop word dictionary--
<entry key= "Remote_ext_stopwords" >location</entry>
Where location refers to a URL, such as http://yoursite.com/getCustomDict, the request only satisfies the following two points to complete the word breaker hot update.
The HTTP request needs to return two headers (header), one is last-modified, one is the ETag, both are string types, as long as there is a change, the plugin will fetch new words to update the thesaurus. The content format returned by the HTTP request is a one-line word break with the newline character \ n. The above two requirements can be achieved by the hot update participle, do not need to restart ES instances.
Hot words that need to be automatically updated can be placed in a UTF-8 encoded. txt file, placed under Nginx or other simple HTTP server, and when the. txt file is modified, the HTTP server automatically returns the corresponding last-modified when the client requests the file. and ETag. You can also make a tool to extract the relevant terms from the business system and update the. txt file.
Build an HTTP request response with the following code:
/** * Get IK custom dictionaries * @param request * @param response */@RequestMapping (value= "/getcustomdict.htm") public void G Etcustomdict (HttpServletRequest request, httpservletresponse response) {try {//Read dictionary file String path = Propertyutil
. Getpro ("Es_ik_dict");
File File = new file (path);
String content = "";
if (file.exists ()) {//Read file contents FileInputStream fi = new FileInputStream (file);
byte[] buffer = new byte[(int) file.length ()];
int offset = 0, numread = 0; while (Offset < buffer.length && (Numread = fi.read (buffer, offset, buffer.length-offset)) >= 0) {of
Fset + = Numread;
} fi.close ();
Content = new String (buffer, "UTF-8");
}//Return Data OutputStream out= response.getoutputstream ();
Response.setheader ("Last-modified", String.valueof (Content.length ()));
Response.setheader ("ETag", String.valueof (Content.length ())); Response.setcontenttype ("Text/plain;
Charset=utf-8 "); Out.write (cOntent.getbytes ("Utf-8"));
Out.flush ();
} catch (Exception e) {e.printstacktrace (); }
}
Update the dictionary name to CustomDict.txt and encode for Utf-8.
The IK configuration file IKAnalyzer.cfg.xml changes configuration as follows:
<?xml version= "1.0" encoding= "UTF-8"?> <!
DOCTYPE Properties SYSTEM "Http://java.sun.com/dtd/properties.dtd" >
<properties>
<comment> IK Analyzer Extended Configuration </comment>
<!--users can configure their own extension dictionaries here--
<entry key= "Ext_dict" >custom/ Mydict.dic;custom/single_word_low_freq.dic;custom/sougou.dic</entry>
<!--users can configure their own extension stop word dictionary here-- >
<entry key= "Ext_stopwords" >custom/ext_stopword.dic</entry>
<!--Users can configure the remote extension dictionary here-- >
<entry key= "Remote_ext_dict" >http://192.168.1.152:8080/tour/interface/getcustomdict.htm</ Entry>
<!--Users can configure the remote extension Stop word dictionary here-
<!--<entry key= "Remote_ext_stopwords" >words_ Location</entry>-
</properties>
Start the HTTP service first, and then start the ES service, ES start log as follows:
[2017-08-11t16:37:31,267] [INFO] [O.w.a.d.monitor] Try load config from D:\elasticsearch-5.5.0-standalone\config\analysis-ik\IKAnalyzer.cfg.xml [ 2017-08-11t16:37:31,283][info][o.w.a.d.monitor] Try load config from D:\elasticsearch-5.5.0-standalone\plugins\
Ik\config\ikanalyzer.cfg.xml [2017-08-11t16:37:31,392][info][o.w.a.d.monitor] [Dict Loading] Custom\mydict.dic [2017-08-11t16:37:31,392] [INFO] [O.w.a.d.monitor] [Dict Loading] custom\single_word_low_freq.dic [2017-08-11t16:37:31,392][info][o.w.a.d.Monito R] [Dict Loading] custom\sougou.dic [2017-08-11t16:37:31,837][info][o.w.a.d.monitor] [Dict Loading] H ttp://localhost:8080/tour/web/esconfig/getcustomdict.htm [2017-08-11t16:37:31,852][info][o.w.a.d.Monitor] Zzu11 9 [2017-08-11t16:37:31,852][info][o.w.a.d.monitor] Archer [2017-08-11t16:37:31,852][info][o.w.a.d.Monitor ] Anchor [2017-08-11t16:37:31,852][info][o.w.a.d.monitor] Xiao Ming [2017-08-11t16:37:31,852][info][o.w.a.d.monitor] Houliangping [2017-08-11t16:37:31,852][info][o.w.a.d.monitor] [Di CT Loading] custom\ext_stopword.dic [2017-08-11t16:37:31,852][info][o.w.a.d.monitor] Reload dictionary complete ...
Reference Document: Http://www.cnblogs.com/liang1101/p/7282744.html