elasticsearch-analysis-ik 左手的ㄟ右手 2022-07-14 01:24 155阅读 0赞 elasticsearch-analysis-ik 一、elasticsearch-analysis-ik的安装与配置 下载插件elasticsearch-analysis-ik并安装 源码地址: https://github.com/medcl/elasticsearch-analysis-ik 在ES的配置文件config/elasticsearch.yml中增加ik的配置,在最后增加: index: analysis: analyzer: ik: alias: [ik_analyzer] type: org.elasticsearch.index.analysis.IkAnalyzerProvider ik_max_word: type: ik use_smart: false ik_smart: type: ik use_smart: true 或 index.analysis.analyzer.ik.type : “ik” 二、词库的配置 IKAnalyzer.cfg.xml的位置可能在如下目录 {conf}/analysis-ik/config/IKAnalyzer.cfg.xml {plugins}/elasticsearch-analysis-ik-*/config/IKAnalyzer.cfg.xml 按照如下说明修改: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>IK Analyzer 扩展配置</comment> <!--用户可以在这里配置自己的扩展字典 --> <entry key="ext_dict">custom/mydict.dic;custom/single_word_low_freq.dic</entry> <!--用户可以在这里配置自己的扩展停止词字典--> <entry key="ext_stopwords">custom/ext_stopword.dic</entry> <!--用户可以在这里配置远程扩展字典 --> <entry key="remote_ext_dict">location</entry> <!--用户可以在这里配置远程扩展停止词字典--> <entry key="remote_ext_stopwords">http://xxx.com/xxx.dic</entry> </properties> 三、使用 curl -XPOST http://localhost:9200/index/fulltext/_mapping -d' { "fulltext": { "_all": { "analyzer": "ik_max_word", "search_analyzer": "ik_max_word", "term_vector": "no", "store": "false" }, "properties": { "content": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_max_word", "include_in_all": "true", "boost": 8 } } } }' 查询 curl -XPOST http://localhost:9200/index/fulltext/_search -d' { "query" : { "match" : { "content" : "中国" }}, "highlight" : { "pre_tags" : ["<tag1>", "<tag2>"], "post_tags" : ["</tag1>", "</tag2>"], "fields" : { "content" : {} } } } '
还没有评论,来说两句吧...