环境
- Elasticsearch 7.1.1;
- elasticsearch-analysis-ik-7.1.1.zip;
- CENTOS 7;
安装
1.在线安装
[inspur@localhost elasticsearch-7.1.1]$ pwd
/home/inspur/elasticsearch/elasticsearch-7.1.1
[inspur@localhost elasticsearch-7.1.1]$ ll
total 532
drwxr-xr-x. 2 inspur inspur 4096 May 23 22:06 bin
drwxr-xr-x. 2 inspur inspur 207 Jun 11 12:54 config
drwxrwxr-x. 3 inspur inspur 19 Jun 6 10:14 data
-rw-rw-r--. 1 inspur inspur 47920 Jun 12 11:21 es.log
drwxr-xr-x. 8 inspur inspur 96 May 23 22:06 jdk
drwxr-xr-x. 3 inspur inspur 4096 May 23 22:06 lib
-rw-r--r--. 1 inspur inspur 13675 May 23 22:01 LICENSE.txt
drwxr-xr-x. 2 inspur inspur 4096 Jun 12 09:41 logs
drwxr-xr-x. 29 inspur inspur 4096 May 23 22:06 modules
-rw-r--r--. 1 inspur inspur 447478 May 23 22:06 NOTICE.txt
drwxr-xr-x. 3 inspur inspur 31 Jun 12 10:44 plugins
-rw-r--r--. 1 inspur inspur 8478 May 23 22:01 README.textile
[inspur@localhost elasticsearch-7.1.1]$ ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.1.1/elasticsearch-analysis-ik-7.1.1.zip
-> Downloading https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.1.1/elasticsearch-analysis-ik-7.1.1.zip
[=================================================] 100%
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: plugin requires additional permissions @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.net.SocketPermission * connect,resolve
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.
Continue with installation? [y/N]y
-> Installed analysis-ik
[inspur@localhost elasticsearch-7.1.1]$
2.离线安装
下载安装包elasticsearch-analysis-ik-7.1.1.zip
,然后进入elasticsearch的bin目录。
sudo ./elasticsearch-plugin install file:///home/michael/elasticsearch-analysis-ik-7.1.1.zip
测试
1.创建索引
curl -XPUT 'http://10.47.0.96:9200/data_archives'
2.创建mapping映射
curl -H 'Content-Type: application/json' -XPOST 'http://10.47.0.96:9200/data_archives/_mapping' -d'
{
"properties": {
"reporterName": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}'
3.查看映射
curl -H 'Content-Type: application/json' -XGET 'http://10.47.0.96:9200/data_archives/_mapping?pretty'
4.初始化文档
curl -H 'Content-Type: application/json' -XPOST 'http://10.47.0.96:9200/data_archives/_doc/1' -d'
{
"reporterId": "1",
"reporterName": "张三",
"birthDay": "2019/06/05"
}'
curl -H 'Content-Type: application/json' -XPOST 'http://10.47.0.96:9200/data_archives/_doc/2' -d'
{
"reporterId": "2",
"reporterName": "李四",
"birthDay": "2019/06/05"
}'
curl -H 'Content-Type: application/json' -XPOST 'http://10.47.0.96:9200/data_archives/_doc/3' -d'
{
"reporterId": "3",
"reporterName": "王五",
"birthDay": "2019/06/12"
}'
5.查看分词效果
curl -H 'Content-Type: application/json' -XPOST 'http://10.47.0.96:9200/data_archives/_analyze?pretty' -d'
{
"analyzer": "ik_max_word",
"text": "中华人民共和国"
}'
6.高亮查询
curl -H 'Content-Type: application/json' -XPOST 'http://10.47.0.96:9200/data_archives/_search?pretty' -d'
{
"query" : { "match" : { "reporterName" : "王" }},
"highlight" : {
"pre_tags" : ["<tag1>", "<tag2>"],
"post_tags" : ["</tag1>", "</tag2>"],
"fields" : {
"reporterName" : {}
}
}
}'
7.返回结果
{
"took" : 12,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.9808292,
"hits" : [
{
"_index" : "data_archives",
"_type" : "_doc",
"_id" : "c40a4e80b4314691ba8c27c22772e19d",
"_score" : 0.9808292,
"_source" : {
"reporterId" : "3",
"reporterName" : "王五",
"birthDay" : "2019/06/06"
},
"highlight" : {
"reporterName" : [
"<tag1>王</tag1>五"
]
}
}
]
}
}
参考: