Releases · medcl/elasticsearch-analysis-ik · GitHubThe IK Analysis plugin integrates Lucene IK analyzer into elasticsearch, support customized dictionary. - Releases · medcl/elasticsearch-analysis-ikhttps://github.com/medcl/elasticsearch-analysis-ik/releases?after=v7.5.2
解压到es的plugin目录下
ik_max_word: 会将文本做最细粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,中华人民,中华,华人,人民共和国,人民,人,民,共和国,共和,和,国国,国歌”,会穷尽各种可能的组合,适合 Term Query;
ik_smart: 会做最粗粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,国歌”,适合 Phrase 查询。
# 创建索引ik_max_word
PUT books
{
"mappings": {
"properties":{
"title":{
"type":"text",
"analyzer": "ik_max_word"
},
"price":{
"type":"integer"
},
"addr":{
"type":"keyword"
},
"company":{
"properties":{
"name":{"type":"text"},
"company_addr":{"type":"text"},
"employee_count":{"type":"integer"}
}
},
"publish_date":{"type":"date","format":"yyy-MM-dd"}
}
}
}
# 插入数据
PUT books/_doc/1
{
"title":"大头儿子小偷爸爸",
"price":100,
"addr":"北京天安门",
"company":{
"name":"我爱北京天安门",
"company_addr":"我的家在东北松花江傻姑娘",
"employee_count":10
},
"publish_date":"2019-08-19"
}
PUT books/_doc/2
{
"title":"白雪公主和十个小矮人",
"price":"99",
"addr":"黑暗森里",
"company":{
"name":"我的家乡在上海",
"company_addr":"朋友一生一起走",
"employee_count":10
},
"publish_date":"2018-05-19"
}
GET books/_mapping
# 查看分词
GET _analyze
{
"analyzer": "ik_max_word",
"text": "白雪公主和十个小矮人"
}
# 查看文档
GET books/_search
{
"query": {
"match": {
"title": "十"
}
}
}
# 创建索引 ik_smart
PUT books2
{
"mappings": {
"properties":{
"title":{
"type":"text",
"analyzer": "ik_smart"
},
"price":{
"type":"integer"
},
"addr":{
"type":"keyword"
},
"company":{
"properties":{
"name":{"type":"text"},
"company_addr":{"type":"text"},
"employee_count":{"type":"integer"}
}
},
"publish_date":{"type":"date","format":"yyy-MM-dd"}
}
}
}
PUT books2/_doc/1
{
"title":"大头儿子小偷爸爸",
"price":100,
"addr":"北京天安门",
"company":{
"name":"我爱北京天安门",
"company_addr":"我的家在东北松花江傻姑娘",
"employee_count":10
},
"publish_date":"2019-08-19"
}
#
PUT books2/_doc/2
{
"title":"白雪公主和十个小矮人",
"price":"99",
"addr":"黑暗森里",
"company":{
"name":"我的家乡在上海",
"company_addr":"朋友一生一起走",
"employee_count":10
},
"publish_date":"2018-05-19"
}
# 查看分词
GET _analyze
{
"analyzer": "ik_smart",
"text": "白雪公主和十个小矮人"
}
# 查看文档
GET books2/_search
{
"query": {
"match": {
"title": "十个"
}
}
}