ruby-on-rails – Custom Analyzer elasticsearch-rails

我在我的Rails应用程序中使用 elasticsearch-rails gem来简化与Elasticsearch的集成.我正在尝试使用 phonetic analysis plugin,所以我需要为我的索引定义自定义分析器和自定义过滤器.

我尝试了这段代码,以便使用soundex语音过滤器执行自定义分析,但它失败并显示异常消息:

[!!!] Error when creating the index: Elasticsearch::Transport::Transport::Errors::BadRequest
[400] {“error”:”MapperParsingException[mapping [call_sentence]]; nested: MapperParsingException[Analyzer [{tokenizer=standard,filter=[standard,lowercase,Metaphoner]}] not found for field [phonetic]]; “,”status”:400}

# 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

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...