1.下载elasticsearch安装包:Elasticsearch 2.4.6 | Elastic?
? ? ?
? 下载中文分词器:Release v1.10.6 · medcl/elasticsearch-analysis-ik · GitHub
? ? ?
2.安装elasticsearch
rpm -ivh elasticsearch-2.4.6.rpm
3.安装中文分词器插件
?? 首先在elasticsearch安装目录下的 /plugins/下创建目录ik,然后copy elasticsearch-analysis-ik-1.10.6.zip的解压内容到ik目录 ? ? ?? 下,如下图:
? ?
?4.测试
#启动服务
service elasticsearch start
#测试是否安装成功
curl -XGET 'localhost:9200'
? ? 结果如下,则安装成功
{
"name" : "Wrecker",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "uwqbAklAQdSWWid84430Tg",
"version" : {
"number" : "2.4.6",
"build_hash" : "5376dca9f70f3abef96a77f4bb22720ace3340fd",
"build_timestamp" : "2017-07-18T12:17:44Z",
"build_snapshot" : false,
"lucene_version" : "5.5.4"
},
"tagline" : "You Know, for Search"
}
? ?? 测试中文分词
#创建index索引
curl -XPUT http://localhost:9200/index
#定义文档的字段,主要是指定使用IK插件
curl -XPOST http://localhost:9200/index/test/_mapping -d'
{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}'
#添加测试数据
curl -XPOST http://localhost:9200/index/test/1 -d'
{"content":"浪费精力零零九零克己复礼"}'
? 查询
#查询
curl -XPOST http://localhost:9200/index/test/_search?pretty -d'
{
"query" : { "match" : { "content" : "浪费" }},
}'
?查询结果如下则安装成功
??
{
"took" : 13,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.35355338,
"hits" : [ {
"_index" : "index",
"_type" : "test",
"_id" : "1",
"_score" : 0.35355338,
"_source" : {
"content" : "浪费精力零零九零克己复礼"
}
} ]
}
}
? ?