ElasticSearch + kibana 部署略
创建索引
PUT /nba_{"mappings": {"properties": {"age": {"type": "integer"},"birthDay": {"type": "date"},"birthDayStr": {"type": "keyword"},"code": {"type": "text"},"country": {"type": "keyword"},"countryEn": {"type": "keyword"},"displayAffiliation": {"type": "text"},"displayName": {"type": "text","analyzer": "ik_max_word_pinyin", "fields" : {"suggest" : {"type" : "completion","analyzer" : "ik_smart_pinyin","preserve_separators" : true,"preserve_position_increments" : true,"max_input_length" : 50}}},"displayNameEn": {"type": "text"},"draft": {"type": "long"},"heightValue": {"type": "float"},"jerseyNo": {"type": "keyword"},"playYear": {"type": "long"},"playerId": {"type": "keyword"},"position": {"type": "text"},"schoolType": {"type": "text"},"teamCity": {"type": "text"},"teamCityEn": {"type": "text"},"teamConference": {"type": "keyword"},"teamConferenceEn": {"type": "keyword"},"teamName": {"type": "keyword"},"teamNameEn": {"type": "keyword"},"weight": {"type": "text"}}},"settings" : {"index" : {"analysis" : {"analyzer" : {"default" : {"type" : "ik_max_word"}}}},"analysis": {"analyzer": {"ik_smart_pinyin": {"type": "custom","tokenizer": "ik_smart","filter": ["my_pinyin"]},"ik_max_word_pinyin": {"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" : true,"limit_first_letter_length" : 16,"lowercase" : true,"remove_duplicated_term" : true}}}}}
自定义ik_smart_pinyin
ik_max_word_pinyin
分词器
分别基于my_pinyin + ik_max_word
和my_pinyin + ik_smart
创建自定义分词器my_pinyin
定义拼音分词过滤displayName
字段使用ik_max_word_pinyin
使用 拼音 汉字 双检索, 并 添加suggest
检索补全pinyin
插件可选参数说明
导入数据
POST /nba_/_doc/566{"countryEn": "Croatia","teamName": "快船","birthDay": 858661200000,"country": "克罗地亚","teamCityEn": "LA","code": "ivica_zubac","displayAffiliation": "Croatia","displayName": "伊维察 祖巴茨哥哥","schoolType": "","teamConference": "西部","teamConferenceEn": "Western","weight": "108.9 公斤","teamCity": "洛杉矶","playYear": 3,"jerseyNo": "40","teamNameEn": "Clippers","draft": ,"displayNameEn": "Ivica Zubac","heightValue": 2.16,"birthDayStr": "1997-03-18","position": "中锋","age": 22,"playerId": "1627826"}
校验汉字分词是否有效
GET /nba_/_search{"query": {"match": {"displayName": "伊维察"}}}
校验拼音分词是否有效
GET /nba_/_search{"query": {"match": {"displayName": "yi wei"}}}
校验汉字补全是否生效
POST /nba_/_search{"suggest": {"my-suggestion": {"text": "伊维","completion": {"field": "displayName.suggest"}}}}
校验拼音补全是否生效
POST /nba_/_search{"suggest": {"my-suggestion": {"text": "yi wei","completion": {"field": "displayName.suggest"}}}}