# ES安装IK插件 ## 1. 参考 [IK Analysis for Elasticsearch](https://github.com/medcl/elasticsearch-analysis-ik) 官方文档 - 下载时,**切换到ES用户(例如 es)**,避免后续解压、运行时出现权限问题 ### 1.1. 下载 IK 插件 ```cmd $ wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.4.2/elasticsearch-analysis-ik-7.4.2.zip ``` ### 1.2. 创建 IK 插件目录 ```cmd $ cd es根目录/plugins/ && mkdir ik ``` ### 1.3. 解压 IK 插件压缩包到 es根目录/plugins/ik 目录 ## 2. 重启 Elasticsearch 先 kill 在[启动](https://www.elastic.co/guide/en/elasticsearch/reference/current/starting-elasticsearch.html#_running_as_a_daemon) ```cmd # 守护进程 $ ./bin/elasticsearch -d -p pid ``` ## 3. 验证安装 - [Quick Example](https://github.com/medcl/elasticsearch-analysis-ik#quick-example) - 创建user索引后重启user服务 ## 4. 建立用户分词 ```cmd curl -XPOST http://10.1.0.175:9200/user/userentity curl -XPOST http://10.1.0.175:9200/user/_mapping -H 'Content-Type:application/json' -d' { "properties": { "content": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" } } }' ``` 上面命令失败时,用这个 ```yaml 创建user索引 curl -X PUT "10.0.1.122:9200/user?include_type_name=true" -H 'Content-Type: application/json' -d' { "settings": { "number_of_shards": 1, "number_of_replicas": 0 }, "mappings": { "userentity": { "properties": { "location": { "type": "geo_point" } } } } } ' ``` ## 附 ES 常用命令 查看es进程 ```cmd $ ps -ef | grep elastic ``` 启动进程 注意不要是 root 用户,否则启动会失败 ```cmd $ ./elasticsearch -d ```