Elasticsearch docker 中文分词 安装

2021-01-30  本文已影响0人  程序员大春

编写执行脚本

docker run -p 9200:9200 -p 9300:9300 --name ${APP_NAME} -e "discovery.type=single-node" -e "cluster.name=elasticsearch" -v $PWD/data:/usr/share/elasticsearch/data -v $PWD/plugins:/usr/share/elasticsearch/plugins -d elasticsearch:7.9.3

执行run.sh

sh run.sh

启动失败没关系。是因为目录权限问题 将当前目录下的data目录权限就可以了

chmod 777 data

开始安装IK分词器

cd plugins
mkdir ik
cd ik
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.9.3/elasticsearch-analysis-ik-7.9.3.zip
docker restart es

检查是否安装成功

curl -XPUT http://localhost:9200/index

检查分词器是否有效

curl -XPOST http://localhost:9200/index/_mapping -H 'Content-Type:application/json' -d'
{
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_smart"
            }
        }

}'

curl -XPOST http://localhost:9200/index/_create/1 -H 'Content-Type:application/json' -d'
{"content":"美国留给伊拉克的是个烂摊子吗"}
'

curl -XPOST http://localhost:9200/index/_search  -H 'Content-Type:application/json' -d'
{
    "query" : { "match" : { "content" : "美国" }},
    "highlight" : {
        "pre_tags" : ["<tag1>", "<tag2>"],
        "post_tags" : ["</tag1>", "</tag2>"],
        "fields" : {
            "content" : {}
        }
    }
}
'
上一篇 下一篇

猜你喜欢

热点阅读