1.下载镜像
1.1存储和检索数据
docker pull elasticsearch:7.4.2
1.2可视化检索数据
docker pull kibana:7.4.2
2.创建elasticsearch实例
创建本地挂载数据卷配置目录
mkdir -p /software/elasticsearch/config
创建本地挂载数据卷数据目录
mkdir -p /software/elasticsearch/data
写入远程任何机器访问配置
echo "http.host: 0.0.0.0" >> /software/elasticsearch/config/elasticsearch.yml
9200 发送http请求端口
9300 es分布式集群状态下节点通信端口
"discovery.type=single-node" 单节点模式运行
ES_JAVA_OPTS="-Xms64m-Xmx256m" 指定es运行最小,最大内存
chmod -R 777 /software/elasticsearch/ 设置权限
未设置权限:"Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes"
docker run -d -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx256m" -v /software/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /software/elasticsearch/data:/usr/share/elasticsearch/data -v /software/elasticsearch/plugins:/usr/share/elasticsearch/plugins --name=elasticsearch7.4.2 elasticsearch:7.4.2
3.创建Kibana实例
ELASTICSEARCH_HOSTS 指定ES主机地址
docker run -d -p 5601:5601 -e ELASTICSEARCH_HOSTS=http://192.168.179.101:9200 --name=kibana7.4.2 kibana:7.4.2
4.安装分词器插件
1.解压
elasticsearch-analysis-ik 7.4.2版本(与ES版本一致)
将下载的分词器压缩包 解压到 本地挂载数据卷插件目录,解压完成后会同步到docker elasticsearch容器/usr/share/elasticsearch/plugins插件目录下
2.进入elasticsearch容器内部查看是否已同步
docker exec -it elasticsearch7.4.2 /bin/bash
3.更改ik目录权限
chmod -R 777 ik/
4.验证ik分词器是否安装好
进入elasticsearch bin目录执行elasticsearch-plugin list(列出安装好的ES插件)
5.重启ES容器实例
6.kibana中使用ik分词器
POST _analyze
{
"analyzer": "ik_smart",
"text": "I人的项目"
}
I人是一组词,但未识别,所以需要自定义扩展一些分词
{
"tokens" : [
{
"token" : "i",
"start_offset" : 0,
"end_offset" : 1,
"type" : "ENGLISH",
"position" : 0
},
{
"token" : "人",
"start_offset" : 1,
"end_offset" : 2,
"type" : "CN_CHAR",
"position" : 1
},
{
"token" : "的",
"start_offset" : 2,
"end_offset" : 3,
"type" : "CN_CHAR",
"position" : 2
},
{
"token" : "项目",
"start_offset" : 3,
"end_offset" : 5,
"type" : "CN_WORD",
"position" : 3
}
]
}
7.自定义扩展分词(通过nginx)
7.1 nginx中添加分词库(fenci.txt)
docker运行nginx容器实例可参考:https://blog.csdn.net/Java_Scholar0/article/details/140708367
将拓展的分词库放在nginx中,让ik分词器给nginx发请求,获取拓展的词库。
html文件夹下创建es文件夹并在其内创建fenci.txt文本,把拓展的分词加入到fenci.txt文本中
访问fenci.txt资源
http://192.168.179.101/es/fenci.txt
7.2配置ik分词器远程扩展分词地址
修改ik分词器配置文件
/software/elasticsearch/plugins/ik/config
将nginx中添加的分词库地址填写进去
7.3 重启ES容器
docker restart elasticsearch7.4.2
7.4 测试自定义扩展分词
POST _analyze
{
"analyzer": "ik_smart",
"text": "I人的项目"
}
发现I人没有被分割,则配置成功
{
"tokens" : [
{
"token" : "i人",
"start_offset" : 0,
"end_offset" : 2,
"type" : "CN_WORD",
"position" : 0
},
{
"token" : "的",
"start_offset" : 2,
"end_offset" : 3,
"type" : "CN_CHAR",
"position" : 1
},
{
"token" : "项目",
"start_offset" : 3,
"end_offset" : 5,
"type" : "CN_WORD",
"position" : 2
}
]
}