1、先下載ik分詞和pinyin分詞,並放到esplugins相應目錄中
2、定義ik分詞后的pinyin分詞器,即定義一個自定義分詞器ik_pinyin_analyzer
#刪除索引 DELETE common_poi #創建索引 PUT common_poi { "settings": { "number_of_shards": 1, "number_of_replicas": 0 } } #關閉索引 POST common_poi/_close #自定義分詞器(ik分器詞和拼音分詞) PUT common_poi/_settings { "settings": { "index": { "analysis": { "analyzer": { "ik_pinyin_analyzer": { "type": "custom", "tokenizer": "ik_max_word", "filter": ["my_pinyin"] } }, "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 } } } } } } #字段映射 PUT common_poi/_mappings { "dynamic":false, "properties":{ "id":{ "type":"long" }, "name":{ "type":"text", "index":true, "analyzer":"ik_pinyin_analyzer" }, "longitude":{ "type":"double" }, "latitude":{ "type":"double" }, "address":{ "type":"text", "index":true, "analyzer":"ik_max_word" }, "phone":{ "type":"text", "index":true }, "type":{ "type":"text", "index":true, "analyzer":"ik_max_word" }, "realType":{ "type":"text", "index":true, "analyzer":"ik_max_word" } } } #打開索引 POST common_poi/_open #條件搜索 GET common_poi/_search { "query": { "match": { "name": "can飲" } } }