ruby-on-rails – Custom Analyzer elasticsearch-rails
发布时间:2020-12-17 04:32:29 所属栏目:百科 来源:网络整理
导读:我在我的Rails应用程序中使用 elasticsearch-rails gem来简化与Elasticsearch的集成.我正在尝试使用 phonetic analysis plugin,所以我需要为我的索引定义自定义分析器和自定义过滤器. 我尝试了这段代码,以便使用soundex语音过滤器执行自定义分析,但它失败并
我在我的Rails应用程序中使用
elasticsearch-rails gem来简化与Elasticsearch的集成.我正在尝试使用
phonetic analysis plugin,所以我需要为我的索引定义自定义分析器和自定义过滤器.
我尝试了这段代码,以便使用soundex语音过滤器执行自定义分析,但它失败并显示异常消息:
# Set up index configuration and mapping # settings index: { number_of_shards: 1,number_of_replicas: 0 } do mapping do indexes :text,type: 'multi_field' do indexes :processed,analyzer: 'snowball' indexes :phone,{analyzer: { tokenizer: "standard",filter: ["standard","lowercase","metaphoner"] },filter: { metaphoner: { type: "phonetic",encoder: "soundex",replace: false } }} indexes :raw,analyzer: 'keyword' end end end 解决方法
您也可以在设置调用中指定它:
settings index: { number_of_shards: 1,number_of_replicas: 0,analysis: { filter: { metaphoner: { type: 'phonetic',encoder: doublemetaphone,replace: true,} },analyzer: { phonetic_analyzer: { tokenizer: 'standard',"metaphoner"],} } } } do mapping do indexes :text,type: 'multi_field' do indexes :processed,analyzer: 'snowball' indexes :phone,analyzer: 'phonetic_analyzer' indexes :raw,analyzer: 'keyword' end end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |