首先需要安装jdk,去oracle.com下载jdk1.8.rpm包
然后yum localinstall jdk-8u121-linux-x64.rpm -y
配置环境变量:修改/etc/下面的profile文件,追加下面2行
export JAVA_HOME=/usr/java/jdk1.8.0_121
export PATH=$PATH:$JAVA_HOME/bin
去https://www.elastic.co/downloads/past-releases/elasticsearch-2-3-5下载 elasticsearch 压缩包
去https://github.com/medcl/elasticsearch-analysis-ik/tree/v1.9.5下载 ik中文分词器 压缩包
运行elasticsearchunzip elasticsearch.zip
bin/elasticsearch -d 后台方式启动
配置ik中文分词器unzip ik.zip
首先要有maven环境,解压出来的是一个maven项目
mvn -package
生成target/releases/elasticsearch-analysis-ik-{version}.zip 将这个ik.zip拷贝到elasticsearch的plugins/
mkdir ik unzip ik.zip -d ik/
重启elasticsearch
运行curl localhost:9200/
得到的响应:
{
"name" : "Baron Von Blitzschlag",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "2.3.5",
"build_hash" : "90f439ff60a3c0f497f91663701e64ccd01edbb4",
"build_timestamp" : "2016-07-27T10:36:52Z",
"build_snapshot" : false,
"lucene_version" : "5.5.0"
},
"tagline" : "You Know, for Search"
}
2.0以上的版本不需要做额外的配置
查看ik中文分词器的效果:
curl http://localhost:9200/_analyze?analyzer=ik -d '男人的衣柜'
{"tokens":[
{"token":"男人","start_offset":0,"end_offset":2,"type":"CN_WORD","position":0},
{"token":"衣柜","start_offset":3,"end_offset":5,"type":"CN_WORD","position":1},
{"token":"衣","start_offset":3,"end_offset":4,"type":"CN_WORD","position":2},
{"token":"柜","start_offset":4,"end_offset":5,"type":"CN_CHAR","position":3}]}
[root@centos elasticsearch-2.3.5]#
ik的配置文件说明<?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>
需要注意的是自定义词库的编码必须是utf-8
如果要开启外网访问,请修改配置文件 config/elasticsearch.yml
network.host: 0.0.0.0
[root@ elasticsearch-2.3.5]# firewall-cmd --add-port=9200/tcp --permanent
success
[root@ elasticsearch-2.3.5]# firewall-cmd --add-port=9300/tcp --permanent
success
[root@ elasticsearch-2.3.5]# firewall-cmd --reload