700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > elasticsearch-7.15.2 同时支持中文ik分词器和pinyin分词器

elasticsearch-7.15.2 同时支持中文ik分词器和pinyin分词器

时间:2020-01-12 13:36:50

相关推荐

elasticsearch-7.15.2 同时支持中文ik分词器和pinyin分词器

文章目录

1. 自定义分词器2. 映射模型3. 效果图
1. 自定义分词器

ES如何支持拼音和中文分词 ?

自定义分词器 支持拼音和中文分词

PUT /jd_goods{"settings": {"analysis": {"analyzer": {"ik_smart_pinyin": {"type": "custom","tokenizer": "ik_smart","filter": ["my_pinyin", "word_delimiter"]},"ik_max_word_pinyin": {"type": "custom","tokenizer": "ik_max_word","filter": ["my_pinyin", "word_delimiter"]}},"filter": {"my_pinyin": {"type" : "pinyin","keep_separate_first_letter" : true,"keep_full_pinyin" : true,"keep_original" : true,"limit_first_letter_length" : 16,"lowercase" : true,"remove_duplicated_term" : true}}}}}

2. 映射模型

重新指定文档类型映射拼音分词类型

POST /jd_goods/_mapping{"properties": {"title": {"type": "text","analyzer": "ik_max_word_pinyin","search_analyzer": "ik_smart_pinyin"},"desc": {"type": "text","analyzer": "ik_max_word_pinyin","search_analyzer": "ik_smart_pinyin"},"img": {"type": "text"},"price": {"type": "text"}}}

1.和2.可以合并为下面这一条命令

PUT /jd_goods{"settings": {"analysis": {"analyzer": {"ik_smart_pinyin": {"type": "custom","tokenizer": "ik_smart","filter": ["my_pinyin", "word_delimiter"]},"ik_max_word_pinyin": {"type": "custom","tokenizer": "ik_max_word","filter": ["my_pinyin", "word_delimiter"]}},"filter": {"my_pinyin": {"type" : "pinyin","keep_separate_first_letter" : true,"keep_full_pinyin" : true,"keep_original" : true,"limit_first_letter_length" : 16,"lowercase" : true,"remove_duplicated_term" : true}}}},"mappings": {"properties": {"title": {"type": "text","analyzer": "ik_max_word_pinyin","search_analyzer": "ik_smart_pinyin"},"desc": {"type": "text","analyzer": "ik_max_word_pinyin","search_analyzer": "ik_smart_pinyin"},"img": {"type": "text"},"price": {"type": "text"}}}}

3. 效果图
拼音搜索

中文搜索

具体详细:

请参考elasticsearch-7.15.2 配置IK中文分词器+拼音分词

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。