Elsaticsearch ik同义词配置(版本6.3.2)

xiaoxiao2021-03-01  54

Elsaticsearch ik同义词配置(版本6.3.2)

网上修改elasticsearch.yml文件配置同义词针对的是5.x版本,在6.0以上已经不行了,在这里记录一下我的配置过程. 1.创建一个索引

curl -XPUT http://localhost:9200/index

2.关闭索引

curl -XPOST 'localhost:9200/index/_close'

3.创建synonyms.txt 文件,保存为utf-8格式,并注意文件的权限

配置的格式为(前面是同义词,后面是实际存在的词): china,中国

4.配置ik同义词

curl -XPUT http://localhost:9200/index/_settings -H 'Content-Type:application/json' -d' { "index.analysis.analyzer.ik_syno.filter" : [ "my_synonym_filter" ], "index.analysis.analyzer.ik_syno.tokenizer" : "ik_max_word", "index.analysis.analyzer.ik_syno.type" : "custom", "index.analysis.analyzer.ik_syno_smart.filter" : [ "my_synonym_filter" ], "index.analysis.analyzer.ik_syno_smart.tokenizer" : "ik_smart", "index.analysis.analyzer.ik_syno_smart.type" : "custom", "index.analysis.filter.my_synonym_filter.synonyms_path" : "synonyms.txt", "index.analysis.filter.my_synonym_filter.type" : "synonym" }'

以上配置定义了 ik_syno 和 ik_syno_smart 这两个新的 analyzer,分别对应 IK 的 ik_max_word 和 ik_smart 两种分词策略,到此同义词配置已经完成,重启ES即可,搜索时指定分词为ik_syno或ik_syno_smart. 5.创建mapping映射

{ "properties": { "content": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_max_word" }, "title": { "type": "text", "analyzer": "ik_syno", "search_analyzer": "ik_syno" } } }

content 字段使用 ik_max_word 作为 analyzer没有同义词策略,title 字段使用 ik_syno 作为 analyzer 有同义词策略,分别测试即可.

转载请注明原文地址: https://www.6miu.com/read-4199970.html

最新回复(0)