Elasticsearch添加拼音搜索支持
发布日期:2021-07-01 06:08:10
浏览次数:2
分类:技术文章
本文共 3560 字,大约阅读时间需要 11 分钟。
一份不错的资料
一、安装插件
文档:
二、新建索引添加拼音支持
<index>
替换为 实际 index
<type>
替换为 实际 type PUT{ "settings" : { "analysis" : { "analyzer" : { "pinyin_analyzer" : { "tokenizer" : "my_pinyin" } }, "tokenizer" : { "my_pinyin" : { "type" : "pinyin", "keep_first_letter":false, "keep_separate_first_letter" : false, "keep_full_pinyin" : true, "keep_original" : false, "limit_first_letter_length" : 16, "lowercase" : true } } } }, "mappings": { " ": { "properties": { "name": { "type": "text", "index": true, "fields":{ "pinyin":{ "type":"text", "analyzer":"pinyin_analyzer" } } }, "link": { "type": "keyword", "index": false }, "id": { "type": "long" }, "update_time": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" } } } }}
分词测试
GET/_analyze{ "field": "name.pinyin", "text": "内蒙古"}返回{ "tokens": [ { "token": "nei", "start_offset": 0, "end_offset": 1, "type": "word", "position": 0 }, { "token": "meng", "start_offset": 1, "end_offset": 2, "type": "word", "position": 1 }, { "token": "gu", "start_offset": 2, "end_offset": 3, "type": "word", "position": 2 } ]}
二、已有索引添加拼音支持
1、新建索引
PUT{ "mappings": { " ": { "properties": { "name": { "type": "keyword", "index": true }, "link": { "type": "keyword", "index": false }, "id": { "type": "long" }, "update_time": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" } } } }}
2、设置拼音分词器
POST/_closePUT /_settings{ "index": { "analysis": { "analyzer": { "pinyin_analyzer": { "tokenizer": "my_pinyin" } }, "tokenizer": { "my_pinyin": { "type": "pinyin", "keep_first_letter": true, "keep_separate_first_letter": true, "keep_full_pinyin": true, "keep_original": false, "limit_first_letter_length": 16, "lowercase": true } } } }}POST /_open
3、修改mapping,添加拼音分词器
PUT/ /_mapping{ " ": { "properties": { "name": { "type": "keyword", "index": true, "fields":{ "pinyin":{ "type":"text", "analyzer":"pinyin_analyzer" } } }, "link": { "type": "keyword", "index": false }, "id": { "type": "long" }, "update_time": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" } } }}GET /_mapping# 将当前索引的数据重新替换一下当前索引POST /_update_by_query?conflicts=proceed
4、搜索测试
get/_search{ "query_string": { "fields": [ "name", "name.pinyin" ], "query": "王苏川", "default_operator": "AND" }}
参考
转载地址:https://pengshiyu.blog.csdn.net/article/details/103153614 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
表示我来过!
[***.240.166.169]2024年04月09日 16时05分38秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
机器学习之重头戏-特征预处理
2019-05-01
synchronized底层实现及锁的升级、降级
2019-05-01
PermGen space-永久区内存溢出
2019-05-01
Maven继承和聚合
2019-05-01
Apache Kafka:优化部署的 10 种最佳实践
2019-05-01
Leetcode 35. 搜索插入位置 c#
2019-05-01
[9] JMeter-常用函数的使用
2019-05-01
[12] JMeter-结果分析之图形图表
2019-05-01
使用aspose.words 18.6实现pdf文档转换
2019-05-01
Java数组详解
2019-05-01
vs中动态DLL与静态LIB工程中加入版本信息的方法
2019-05-01
大数据分析技术与应用一站式学习(值得收藏)_v20200418
2019-05-01
Qt 在windows下的串口读写
2019-05-01
自定义Starter
2019-05-01
分布式事务原理探究(一)
2019-05-01
spring cloud consul 应用的多实例名的解决
2019-05-01
映 射 ALT 键
2019-05-01
vim使用快捷键F4生成文件头注释、F5生成main函数模板、F6生成.h文件框架模板
2019-05-01
OV5620的视频驱动
2019-05-01