如何使用 docker 在 Ubuntu 22.04 上安装带IK分词器的 Elastic Search 7.10.2

/static/0b6d1bb860672d3f879e2bced82b8bf128b74337b14ee3cdf2ee2e0452823610.png


最近由于某些需求,需要在本地安装一个7.10.2带分词的Elastic Search,这里选择了docker进行安装,安装docker请见:ma101926

这里我选用了官方容器 docker.elastic.co/elasticsearch/elasticsearch:7.10.2

启动官方 7.10.2 镜像

docker run -d --name es-node \

--restart=unless-stopped \

-p 9200:9200 -p 9300:9300 \

-e "discovery.type=single-node" \

-e "network.host=0.0.0.0" \

-e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \

-v es-data:/usr/share/elasticsearch/data \

docker.elastic.co/elasticsearch/elasticsearch:7.10.2

状态检查

docker ps # 应显示 Up

docker logs es-node | tail -5 # 检查无错误

安装IK分词器

进入容器安装 IK 插件(用 Infinilabs 源)

docker exec -it es-node bash

elasticsearch-plugin install https://release.infinilabs.com/analysis-ik/stable/elasticsearch-analysis-ik-7.10.2.zip


输出类似的内容即为安装成功:

-> Installing analysis-ik from https://release.infinilabs.com/...

-> Downloaded

-> Installed analysis-ik

测试结果

# 测试 ES

curl http://localhost:9200


# 测试 IK

curl -X POST "localhost:9200/_analyze" -H 'Content-Type: application/json' -d'

{

"analyzer": "ik_smart",

"text": "你好世界"

}'

输出应为:

{"tokens":[{"token":"你好","start_offset":0,"end_offset":2,"type":"CN_WORD","position":0},{"token":"世界","start_offset":2,"end_offset":4,"type":"CN_WORD","position":1}]}

发布评论
全部评论(0)
最新
最早
加载中...