es6.4.0安裝和配置IK+拼音插件 實現非全拼搜索

安裝IK分詞器html

1、進入到es的plugins文件夾建立文件夾analysis-ik
mkdir analysis-ik
2、下載ik壓縮包文件
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.0/elasticsearch-analysis-ik-6.4.0.zip
3、解壓到當前目錄
unzip elasticsearch-analysis-ik-6.4.0.zip
4、驗證ik是否安裝成功
http://192.168.105.180:9200/_analyze
{
"analyzer": "ik_max_word",
"text": "中華人民共和國國歌"
}git

安裝拼音插件github

1、進入到es的plugins文件夾建立文件夾analysis-pinyin
mkdir analysis-pinyin
2、下載拼音壓縮包文件
wget https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v6.4.0/elasticsearch-analysis-pinyin-6.4.0.zip
3、解壓到當前目錄
unzip elasticsearch-analysis-pinyin-6.4.0.zip
4、驗證拼音插件是否安裝成功
http://192.168.105.180:9200/_analyze
{
"analyzer": "pinyin_analyzer",
"text": "蘇坡蜜"
}app

將ik和拼音插件放到一塊兒的配置elasticsearch

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
                }
            }
        }
    }
}

而後設置mappingspa

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"
          }
        }
      }
    }
  }
}

都設置好之後驗證是否成功.net

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

下面咱們在name字段裏面加一條數據驗證是否成功插件

增長了一條叫「如家酒店」的數據,驗證一下能不能搜到吧code

能夠看到搜索「rj」是能夠匹配到如家酒店的htm

參考文獻:

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

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

相關文章
相關標籤/搜索