ES 同义词设置
作者:互联网
需求场景
查询 土豆 要能得到 马铃薯
官网地址
https://www.elastic.co/guide/en/elasticsearch/reference/8.1/indices-reload-analyzers.html
实现案例
本文使用了 ik 分词器,不知道怎么安装 ik 分词器的去这里:https://github.com/medcl/elasticsearch-analysis-ik
# 第一步,配置索引
PUT /my-index-000001
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"my_synonyms": {
"tokenizer": "ik_smart",
"filter": [ "synonym" ]
}
},
"filter": {
"synonym": {
"type": "synonym_graph",
"synonyms_path": "analysis/synonym.txt",
"updateable": true
}
}
}
}
},
"mappings": {
"properties": {
"text": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "my_synonyms"
}
}
}
}
# 第二步,初始化数据
POST _bulk
{"index":{"_index":"my-index-000001","_id":1}}
{"key1":"1","key2":"11","key3":"111","text":"blue"}
{"index":{"_index":"my-index-000001","_id":2}}
{"key1":"2","key2":"22","key3":"2222","text":"2222"}
{"index":{"_index":"my-index-000001","_id":3}}
{"key1":"3","key2":"33","key3":"333","text":"3333"}
{"index":{"_index":"my-index-000001","_id":4}}
{"key1":"4","key2":"44","key3":"444","text":"4444"}
# 第三步,添加同义词,如果是集群,请修改所有节点上的同义词配置文件
vim /data/elasticsearch1/config/analysis/synonym.txt
# 第四步,刷新分词器,这回重新加载分词器下的同义词
POST /my-index-000001/_reload_search_analyzers
# 清理缓存,重新加载搜索分析器后,您应该清除请求缓存以确保它不包含从以前版本的分析器派生的响应
POST /my-index-000001/_cache/clear?request=true
标签:index,synonym,000001,同义词,ik,设置,text,my,ES 来源: https://www.cnblogs.com/jiangdewen/p/16172679.html