一涉瘾、介紹
// 測(cè)試分詞器
GET _analyze
{
"analyzer": "ik_max_word",
"text": "北京歡迎你"
}
// 構(gòu)建分詞器映射
PUT my_index1
{
"mappings": {
"doc": {
"properties": {
"coontent": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
}
// 實(shí)例
PUT my_index1/doc/1
{
"content": "今天是個(gè)好日子"
}
PUT my_index1/doc/2
{
"今天不想活了"
}
GET my_index1/doc/1
{
"query": {
"match": {
"content": "今天"
}
}
}
二、分詞器對(duì)比
// 構(gòu)建默認(rèn)分詞器映射
PUT my_index2
{
"mappings": {
"doc": {
"properties": {
"coontent": {
"type": "text"
}
}
}
}
}
"""
注意:默認(rèn)分詞器是按照字進(jìn)行一個(gè)一個(gè)分;ik分詞器是按照詞進(jìn)行一個(gè)一個(gè)分
"""
三粱甫、粗細(xì)顆粒對(duì)比
// 構(gòu)建新的分詞器映射
PUT my_index3/doc/_mapping
{
"doc": {
"_all": {
"analyzer": "ik_smart"
},
"properties": {
"title": {
"type": "text"
},
"content": {
"type": "text"
}
}
}
}
"""
注意:smart分詞器就會(huì)更加粗胜宇,如查詢"今天",會(huì)相應(yīng)地將沒(méi)有"今天"的詞語(yǔ)對(duì)應(yīng)的數(shù)據(jù)也查詢出來(lái)
"""
四耀怜、短語(yǔ)和短語(yǔ)前綴查詢
// 短語(yǔ)查詢
GET my_index3/doc/_search
{
"query": {
# 查詢中文短語(yǔ)推薦
"match_parse": {
"content": "白話"
}
}
}
// 短語(yǔ)前綴查詢
GET my_index3/doc/_search
{
"query": {
# 以"白話"開頭進(jìn)行查詢
"match_parse_prefix": {
"content": "白話"
}
}
}