ElasticSearch6 IK 同义词 配置
at 4年前 ca elasticsearch pv 2130 by touch
1. 创建一个索引
curl -v -X PUT localhost:9200/station_index
2. close index,因为我们接下来要对该索引设置
curl -XPOST 'localhost:9200/station_index/_close'
3. 配置ik同义词
curl -l -H "Content-Type:application/json" -H "Accept:application/json" -X PUT 'http://localhost:9200/station_index/_settings?preserve_existing=true' -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"}'
如 synonyms.txt 发生变动,重启 es 服务器即可生效
我遇到的问题:
问题1:这里说一下,网上很多博客 修改 elasticsearch.yml 的做法,在 es6 中无法使用,例如:
es 服务器 告诉我 ,自从5.x 以后他们就不让这么做啦,只能通过访问 API 来设置,好吧,我直接复制改一下索引搞定
问题2:"type":"malformed_input_exception","reason":"Input length = 1"
详细信息如下
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"failed to build synonyms"}],"type":"illegal_argument_exception","reason":"failed to build synonyms","caused_by":{"type":"malformed_input_exception","reason":"Input length = 1"}},"status":400}
原因:这个问题是由于 synonyms.txt 解析错误造成
1)检查你的语法配置是否如下
程王, 程王线 => 程王
2)编码 UTF-8 (很关键!!!我就是被坑在这里)
4. open index
curl -XPOST 'localhost:9200/station_index/_open'
5. 测试
curl -l -H "Content-Type:application/json" -H "Accept:application/json" -X POST 'http://localhost:9200/station_index/_analyze' -d '{ "analyzer" : "ik_syno_smart", "text" : "程王线"}'
到这里已经大功告成了!
下面再把我的映射贴出来,有需要的可以参考
curl -l -H "Content-Type:application/json" -H "Accept:application/json" -X POST 'localhost:9200/station_index/station/_mapping' -d '{ "properties": { "name": { "type": "text", "analyzer": "ik_syno_smart", "search_analyzer": "ik_syno_smart" } }}'
版权声明
本文仅代表作者观点,不代表码农殇立场。
本文系作者授权码农殇发表,未经许可,不得转载。
已有0条评论