Docker安装ElasticSearch和IK分词器

建议使用阿里云镜像加速

参考:https://blog.csdn.net/qq_37495786/article/details/83246421

必须提前创建好yml文件
mkdir -p /mydata/elasticsearch/config
mkdir -p /mydata/elasticsearch/data
echo "http.host: 0.0.0.0" >> /mydata/elasticsearch/config/elasticsearch.yml
不给权限启动会报错
chmod 777 -R /mydata/elasticsearch
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms512m -Xmx2048m" -v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /mydata/elasticsearch/data:/usr/share/elasticsearch/data -v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins -d elasticsearch:7.4.2
测试

查看elasticsearch版本信息: http://192.168.0.163:9200/

{
  "name" : "b4155a6ef926",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "-V7EhH0hR5e69u1e_IgVKg",
  "version" : {
    "number" : "7.4.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "2f90bbf7b93631e52bafb59b3b049cb44ec25e96",
    "build_date" : "2019-10-28T20:40:44.881551Z",
    "build_snapshot" : false,
    "lucene_version" : "8.2.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
kibana启动时指定你自己的ES服务ip
docker run --name kibana -e ELASTICSEARCH_HOSTS=http://192.168.252.128:9200 -p 5601:5601 -d kibana:7.4.2
随docker启动
docker update elasticsearch --restart=always
docker update kibana --restart=always

安装IK分词器

下载,要和ES版本对应

https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.4.2/elasticsearch-analysis-ik-7.4.2.zip

解压到/mydata/elasticsearch/plugins/ik
image.png
重启ES
docker restart elasticsearch
验证
GET _analyze
{
  "analyzer": "ik_smart",
  "text": "我是中国人"
}
输出结果
{
  "tokens" : [
    {
      "token" : "我",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "CN_CHAR",
      "position" : 0
    },
    {
      "token" : "是",
      "start_offset" : 1,
      "end_offset" : 2,
      "type" : "CN_CHAR",
      "position" : 1
    },
    {
      "token" : "中国人",
      "start_offset" : 2,
      "end_offset" : 5,
      "type" : "CN_WORD",
      "position" : 2
    }
  ]
}

你可能感兴趣的:(Docker安装ElasticSearch和IK分词器)