二、Elastic5.5.2安装中文分词器教程及简单测试

一、下载分词器安装包

首先进入各版本下载页面,选择相应的版本进行下载(和自己安装的ElasticSearch版本保持一致)。我这里安装的是5.5.2的ElasticSearch,所以选择对应的5.5.2软件包。

右键·复制下载链接·,在Linux系统中使用wget命令下载

wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.5.2/elasticsearch-analysis-ik-5.5.2.zip

这一步有时候会下载不成功,那么可以使用浏览器本地电脑下载完成后,使用工具上传到服务器目录中。

二、解压并安装

1.移动elasticsearch-analysis-ik-5.5.2.zip到安装目录的plugins目录

[king@localhost soft]$ mv elasticsearch-analysis-ik-5.5.2.zip /soft/elasticsearch-5.5.2/plugins/

2.进入安装目录的plugins目录

[king@localhost soft]$ cd /soft/elasticsearch-5.5.2/plugins/
[king@localhost plugins]$ ls
elasticsearch-analysis-ik-5.5.2.zip  x-pack

3.解压

[king@localhost plugins]$ unzip elasticsearch-analysis-ik-5.5.2.zip 
[king@localhost plugins]$ ls
elasticsearch  elasticsearch-analysis-ik-5.5.2.zip  x-pack

4.删除压缩包(非必须)

[king@localhost plugins]$ rm -rf elasticsearch-analysis-ik-5.5.2.zip 

按照官方说明,这时已经成功安装了,重启ElasticSearch即可。

三、测试

1.创建一个索引

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

2.创建一个映射

curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'
{
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word"
            }
        }

}'

3.索引一些文档,可以认为就是插入一些信息

curl -XPOST http://localhost:9200/index/fulltext/1 -d'
{"content":"美国留给伊拉克的是个烂摊子吗"}
'
curl -XPOST http://localhost:9200/index/fulltext/2 -d'
{"content":"公安部:各地校车将享最高路权"}
'
curl -XPOST http://localhost:9200/index/fulltext/3 -d'
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
'
curl -XPOST http://localhost:9200/index/fulltext/4 -d'
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
'

4.查询,结果以高亮显示

查询

curl -XPOST http://localhost:9200/index/fulltext/_search  -d'
{
    "query" : { "match" : { "content" : "中国" }},
    "highlight" : {
        "pre_tags" : ["<tag1>", "<tag2>"],
        "post_tags" : ["</tag1>", "</tag2>"],
        "fields" : {
            "content" : {}
        }
    }
}
'

结果

{
    "took": 14,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 2,
        "max_score": 2,
        "hits": [
            {
                "_index": "index",
                "_type": "fulltext",
                "_id": "4",
                "_score": 2,
                "_source": {
                    "content": "中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
                },
                "highlight": {
                    "content": [
                        "<tag1>中国</tag1>驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首 "
                    ]
                }
            },
            {
                "_index": "index",
                "_type": "fulltext",
                "_id": "3",
                "_score": 2,
                "_source": {
                    "content": "中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"
                },
                "highlight": {
                    "content": [
                        "均每天扣1艘<tag1>中国</tag1>渔船 "
                    ]
                }
            }
        ]
    }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值