构建拼音索引
Step 1 在ES中安装pinyin分词器
安装步骤详见网上的众多介绍,这里不赘述,ES-pinyin分词器安装。pinyin的开源见:GitHub - medcl/elasticsearch-analysis-pinyin: This Pinyin Analysis plugin is used to do conversionb
Step 2 新建索引并初始化测试数据
PUT idx_test_user
{
"mappings": {
"dynamic": false,
"properties": {
"name": {
"analyzer": "standard",
"type": "text",
"fields": {
"pinyin": {
"type": "text",
"analyzer": "index_pinyin_analyzer"
}
}
}
}
},
"settings": {
"analysis": {
"analyzer": {
"index_pinyin_analyzer": { // MARK 1
"tokenizer": "index_pinyin_tokenizer"
},
"search_pinyin_analyzer": { // MARK 2
"tokenizer": "search_pinyin_tokenzier"
}
},
"tokenizer": {
"index_pinyin_tokenizer": {
"keep_joined_full_pinyin" : "true",
"lowercase" : "true",
"none_chinese_pinyin_tokenize" : "false",
"keep_none_chinese_in_joined_full_pinyin" : "true",
"keep_original" : "true",
"keep_none_chinese_together" : "true",
"remove_duplicated_term" : "false",
"keep_separate_first_letter" : "false",
"type" : "pinyin",
"limit_first_letter_length" : "16",
"keep_full_pinyin" : "true"
},
"search_pinyin_tokenzier": {
"keep_joined_full_pinyin" : "true",
"lowercase" : "true",
"keep_original" : "true",
"remove_duplicated_term" : "false",