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