7

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

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

[!!!] 创建索引时出错:Elasticsearch::Transport::Transport::Errors::BadRequest [400] {"error":"MapperParsingException[mapping [call_sentence]]; 嵌套:MapperParsingException[Analyzer [{tokenizer=标准,过滤器 = [标准,小写,变音器]}] 未找到字段 [语音]]; ","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
4

2 回答 2

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
于 2014-08-25T02:49:25.243 回答
2

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

#################################### Index ####################################
index: 
  analysis: 
    analyzer: 
      phonetic_analyzer: 
        tokenizer: standard
        filter: [metaphoner]
    filter: 
      metaphoner: 
        type: phonetic
        encoder: doublemetaphone
        replace: true
于 2014-08-25T01:32:20.360 回答