定制版Homestead Elasticsearch 6 启动成功后,手动安装IK插件

开发环境解析:软件类型:Homestead定制版,创建索引:成功,9200端口:成功开启,创建类型:提示 ik 报错。因为是应用Homestead定制版已经内置了Elasticsearch软件,如果提示 ik 报错如error(1)说明IK 插件安装失败了,那么需要手动安装IK插件。

Homestead如何开启Elasticsearch ?

Error(1)

vagrant@homestead:~/code/laravel-shop$ curl -H'Content-Type: application/json' -XPUT http://localhost:9200/test_index/_mapping/_doc?pretty -d'{
>   "properties": {
> "title": { "analyzer": "ik_smart","type": "text" },
>     "description": { "analyzer": "ik_smart","type": "text" },
>     "price": { "type": "scaled_float", "scaling_factor": 100 }
>   }
> }'
{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "analyzer [ik_smart] not found for field [description]"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "analyzer [ik_smart] not found for field [description]"
  },
  "status" : 400
}

Homestead 内置Elasticsearch路径:

/usr/share/elasticsearch

接下来是手动安装IK插件解析过程:

1.启用 Elasticsearch

$ sudo systemctl restart elasticsearch.service

Elasticsearch 启动需要时间,稍等大概 10s ~ 一分钟以后,使用以下命令检测是否启动成功:

2.查看Elasticsearch版本

$ curl http://127.0.0.1:9200/
{
  "name" : "g5dF3Jt",
  "cluster_name" : "homestead",
  "cluster_uuid" : "DmzC3oKQS024l4y53kMmtg",
  "version" : {
    "number" : "6.7.0",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "8453f77",
    "build_date" : "2019-03-21T15:32:29.844721Z",
    "build_snapshot" : false,
    "lucene_version" : "7.7.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

看到Elasticsearch版本为6.7.0

3.下载与之相同的IK版本6.7.0

下载地址https://github.com/medcl/elasticsearch-analysis-ik/releases

4.将下载的elasticsearch-analysis-ik软件解压到ik目录,在plugins目录中mkdir:ik

/usr/share/elasticsearch/plugins/ik

5.测试命令创建类型:

$ curl -H'Content-Type: application/json' -XPUT http://localhost:9200/test_index/_mapping/_doc?pretty -d'{
  "properties": {
    "title": { "type": "text", "analyzer": "ik_smart" }, 
    "description": { "type": "text", "analyzer": "ik_smart" },
    "price": { "type": "scaled_float", "scaling_factor": 100 }
  }
}'

提示:

vagrant@homestead:~$ curl -H'Content-Type: application/json' -XPUT http://localhost:9200/test_index/_mapping/_doc?pretty -d'{
>   "properties": {
>     "title": { "type": "text", "analyzer": "ik_smart" },
>     "description": { "type": "text", "analyzer": "ik_smart" },
>     "price": { "type": "scaled_float", "scaling_factor": 100 }
>   }
> }'
{
  "acknowledged" : true
}

说明 IK 插件安装成功

阅读 531

Comments