Elasticsearch配置自定义analyzer后测试提示找不到分析器如何解决
问题原因
你的报错由两处拼写错误导致:
- 自定义分析器配置节点拼写错误:Elasticsearch 识别的分析器配置节点为美式拼写
analyzer,你当前配置中使用了英式拼写analyser,导致 Elasticsearch 无法定位到你声明的 autocomplete 分析器。 - 过滤器命名与引用不匹配:你定义的 edge_ngram 过滤器名称为
autcomplete_filter(缺失字母 o),但在分析器配置的 filter 列表中引用的是autocomplete_filter,即便分析器节点拼写修正后也会触发过滤器找不到的报错。
修复步骤
已创建的索引无法直接修改 analysis 配置,需按以下步骤操作:
- 关闭 movies 索引
curl -XPOST "127.0.0.1:9200/movies/_close"
- 更新索引配置,修正两处拼写错误
curl -XPUT "127.0.0.1:9200/movies/_settings" -H "Content-Type: application/json" -d ' { "analysis": { "filter": { "autocomplete_filter": { "type": "edge_ngram", "min_gram": "1", "max_gram": "20" } }, "analyzer": { "autocomplete": { "filter": [ "lowercase", "autocomplete_filter" ], "type": "custom", "tokenizer": "standard" } } } }'
- 重新打开 movies 索引
curl -XPOST "127.0.0.1:9200/movies/_open"
- 验证分析器效果
curl -XGET "127.0.0.1:9200/movies/_analyze?pretty" -H "Content-Type: application/json" -d ' { "analyzer": "autocomplete", "text": "Sta" }'
操作完成后即可正常返回分词结果。
内容的提问来源于stack exchange,提问作者webmaster Chp
相关产品推荐
相关产品推荐

