一、ES集群搭建,建议在单机部署时安装完IK分词器再copy到其他机器进行集群部署,省去安装IK分词器的时间
1.单机部署,参照https://blog.csdn.net/ab7253957/article/details/85334259中搭建es的步骤,先搭建单机es再进行下面的步骤
2.修改配置文件config/elasticsearch.yml,标红属性是需要修改或增加的属性,如果是在同一台机器部署需要修改端口号
cluster.name: elk
#节点名称
node.name: node-192.168.214.128
node.master: true
node.data: true
#http访问端口
http.port: 9200
#节点通信端口
transport.tcp.port: 9300
#外网访问地址
network.host: 0.0.0.0
discovery.zen.ping.unicast.hosts: ["192.168.214.128:9300", "192.168.214.129:9300"]
#discovery.zen.ping_timeout: 30s #设置超时时间,一般来说网络不是很稳定的话设置长一点
#discovery.zen.minimum_master_nodes: 2 #至少要发现集群中能做master的节点数,配置n(es节点的个数)/2防止脑裂,选举在机器大于3的时候。
3. ./bin/elasticsearch -d 后台启动
二、安装IK分词器
1.IK分词器github地址,https://github.com/medcl/elasticsearch-analysis-ik,里面有安装IK分词器的命令,注意修改版本号,我们使用的es是2.4.6版本,对应ik版本为1.10.6,所以修改命令如下
./bin/plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v1.10.6/elasticsearch-analysis-ik-1.10.6.zip
安装成功后在config目录下会有analysis-ik文件夹,里面是对IK分词器的配置
2.安装过程中遇到如下错误
ERROR: Error copying config directory [/elasticsearch-2.4.6/plugins/analysis-ik/config] to [/elasticsearch-2.4.6/config/analysis-ik], cleaning up, reason: FileSystemException[elasticsearch-2.4.6/config/analysis-ik: 不允许的操作]
用户权限不足,切换到root安装 sudu root
3.测试IK分词器
(1)创建mapping
test-es/estype/_mapping
{
"properties": {
"praise_rate": {
"type": "double"
},
"discription": {
#细粒度分词
"analyzer": "ik_max_word",
"type": "string"
},
"create_time": {
"format": "strict_date_optional_time||epoch_millis",
"type": "date"
},
"level": {
"type": "long"
},
"author": {
#粗粒度分词
"analyzer": "ik_smart",
"type": "string"
},
"isbn": {
"type": "string"
},
"language": {
"type": "long"
},
"type": {
"type": "long"
},
"is_delete": {
"type": "long"
},
"reader_number": {
"type": "long"
},
"imgurl": {
"type": "string"
},
"recommend_number": {
"type": "long"
},
"score": {
"type": "long"
},
"update_time": {
"format": "strict_date_optional_time||epoch_millis",
"type": "date"
},
"word_count": {
"type": "long"
},
"price": {
"type": "double"
},
"name": {
"analyzer": "ik_max_word",
"type": "string"
},
"publishdate": {
"format": "strict_date_optional_time||epoch_millis",
"type": "date"
},
"publisher": {
"type": "string"
},
"id": {
"type": "long"
},
"state": {
"type": "long"
},
"page_count": {
"type": "long"
}
}
}
(2)使用索引
索引名/_analyze
test-es/_analyze
{"field":"discription","text":"我是中国人"}
如图表示成功