2、创建同义词文本维护同义词
- 下载elasticsearch-7.10.0版本,并解压:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-10-0
- 下载IK分词器7.10.0版本,并解压到指定文件夹下(elasticsearch-7.10.0/plugins/),文件夹改名为ik:https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v7.10.0
- 在ES的安装目录下的config目录下新建文件 synonyms.txt,如下图
- 然后在文本中加入同义词如下
双十一,双11=>购物节
中秋,月饼=>中秋节
iphone,苹果手机,iphone13Pro
小米,小米手机
小米,小米电脑
- 启动es,再运行es-head插件,进入可视化页面,执行创建索引操作,并指定同义词文件配置
PUT http://localhost:9200/test02_index/
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0,
"analysis": {
"filter": {
"local_doc_filter": {
"type": "synonym",
"synonyms_path": "synonyms.txt"
}
},
"analyzer": {
"my_doc_syno": {
"type": "custom",
"tokenizer": "ik_smart",
"filter": [
"local_doc_filter"
]
}
}
}
},
"mappings": {
"properties": {
"name": {
"type": "text",
"analyzer": "my_doc_syno"
},
"remark": {
"type": "text",
"analyzer": "my_doc_syno"
}
}
}
}
- 此时可看到正确返回
- 此时,可通过head插件查看到索引属性
- 接下来我们进入到验证环节,看是否同义词设置成功
POST http://localhost:9200/test02_index/_analyze/
{
"field": "name",
"text": "双十一,iphone,小米"
}
数据验证步骤,同第一种方式(传送门:https://blog.youkuaiyun.com/u012888052/article/details/125016668)