Custom Analyzer elasticsearch-rails

bad*_*wym 7 ruby-on-rails elasticsearch elasticsearch-plugin

我在我的Rails应用程序中使用elasticsearch-rails gem来简化与Elasticsearch的集成.我正在尝试使用语音分析插件,因此我需要为我的索引定义自定义分析器和自定义过滤器.

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

[!!!]错误创建索引时:Elasticsearch ::运输::运输::错误::错误请求[400] { "错误":"MapperParsingException [映射[call_sentence]];嵌套:MapperParsingException [分析器[{标记者=标准,过滤= [标准,小写,变音符]}]找不到字段[phonetic]];","状态":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
Run Code Online (Sandbox Code Playgroud)

Cam*_*tin 13

您也可以在设置调用中指定它:

settings index: { 
    number_of_shards: 1, 
    number_of_replicas: 0,
    analysis: {
      filter: {
        metaphoner: { 
          type: 'phonetic',
          encoder: doublemetaphone,
          replace: true,
        } 
      },
      analyzer: {
        phonetic_analyzer: {
          tokenizer: 'standard',
          filter: ["standard", "lowercase", "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
Run Code Online (Sandbox Code Playgroud)


bad*_*wym 2

好吧,我修改了 elasticsearch.yml 配置以包含语音分析器

#################################### Index ####################################
index: 
  analysis: 
    analyzer: 
      phonetic_analyzer: 
        tokenizer: standard
        filter: [metaphoner]
    filter: 
      metaphoner: 
        type: phonetic
        encoder: doublemetaphone
        replace: true
Run Code Online (Sandbox Code Playgroud)