当前位置 : 主页 > 网络推广 > seo >

es6.4.0安装和配置IK+拼音插件 实现非全拼搜索

来源:互联网 收集:自由互联 发布时间:2021-06-16
安装IK分词器 一、进入到es的plugins文件夹创建文件夹analysis-ik mkdir analysis-ik 二、下载ik压缩包文件 wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.0/elasticsearch-analysis-ik-6.4.

安装IK分词器

一、进入到es的plugins文件夹创建文件夹analysis-ik
mkdir analysis-ik
二、下载ik压缩包文件
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.0/elasticsearch-analysis-ik-6.4.0.zip
三、解压到当前目录
unzip elasticsearch-analysis-ik-6.4.0.zip
四、验证ik是否安装成功
http://192.168.105.180:9200/_analyze
{
"analyzer": "ik_max_word",
"text": "中华人民共和国国歌"
}

安装拼音插件

一、进入到es的plugins文件夹创建文件夹analysis-pinyin
mkdir analysis-pinyin
二、下载拼音压缩包文件
wget https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v6.4.0/elasticsearch-analysis-pinyin-6.4.0.zip
三、解压到当前目录
unzip elasticsearch-analysis-pinyin-6.4.0.zip
四、验证拼音插件是否安装成功
http://192.168.105.180:9200/_analyze
{
"analyzer": "pinyin_analyzer",
"text": "苏坡蜜"
}

将ik和拼音插件放到一起的配置

http://192.168.105.180:9200/index/_settings
{
    "index": {
        "analysis": {
            "analyzer": {
                "ik_pinyin_analyzer": {
                    "type": "custom",
                    "tokenizer": "ik_max_word",
                    "filter": [
                        "my_pinyin",
                        "word_delimiter"
                    ]
                }
            },
            "filter": {
                 "my_pinyin" : {
                    "type" : "pinyin",
                    "keep_separate_first_letter" : false,
                    "keep_full_pinyin" : true,
                    "keep_original" : false,
                    "limit_first_letter_length" : 10,
                    "lowercase" : true,
                    "remove_duplicated_term" : true
                }
            }
        }
    }
}

然后设置mapping

http://192.168.105.180:9200/index/folks/_mapping
{
  "folks": {
    "properties": {
      "name": {
        "type": "text",
        "fields": {
          "pinyin": {
            "analyzer": "ik_pinyin_analyzer",
            "term_vector": "with_offsets",
            "boost": 10,
            "type": "text"
          }
        }
      }
    }
  }
}

都设置好以后验证是否成功

http://192.168.105.180:9200/_analyze
 {
  "analyzer": "ik_pinyin_analyzer",
  "text": "如家酒店"
}

下面我们在name字段里面加一条数据验证是否成功

增加了一条叫“如家酒店”的数据,验证一下能不能搜到吧

可以看到搜索“rj”是可以匹配到如家酒店的

参考文献:

https://blog.csdn.net/jinyidong/article/details/79690186 

https://www.cnblogs.com/yijialong/p/9719964.html

网友评论