Elasticsearch添加拼音搜索支持
发布日期:2021-07-01 06:08:10
浏览次数:3
分类:技术文章
本文共 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月14日 02时23分22秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
使用aspose.words 18.6实现pdf文档转换
2019-05-01
Java数组详解
2019-05-01
vs中动态DLL与静态LIB工程中加入版本信息的方法
2019-05-01
大数据分析技术与应用一站式学习(值得收藏)_v20200418
2019-05-01
自定义Starter
2019-05-01
映 射 ALT 键
2019-05-01
vim使用快捷键F4生成文件头注释、F5生成main函数模板、F6生成.h文件框架模板
2019-05-01
OV5620的视频驱动
2019-05-01
C++中两个类交叉定义或递归定义的解决办法
2019-05-01
记一次Hive 行转列 引起的GC overhead limit exceeded
2019-05-01
OpenGL ES八 - 交叉存取顶点数据
2019-05-01
crontab定时任务写法
2019-05-01
nginx: [emerg] unknown directive "if($remote_addr" in /usr/local/tools/nginx/conf/nginx.conf:57
2019-05-01
module pip has no attribute main问题解决
2019-05-01
LeetCode 134.Gas Station (加油站)
2019-05-01
Python之命名元组 (namedtuple)
2019-05-01
使用libpcap过滤arp
2019-05-01
[转帖]Robots.txt指南
2019-05-01
多用户与多租户的区别
2019-05-01