[英]Custom Analyzer elasticsearch-rails
I'm using elasticsearch-rails gem in my Rails app to simplify integration with Elasticsearch. 我在我的Rails应用程序中使用elasticsearch-rails gem来简化与Elasticsearch的集成。 I'm trying to use the phonetic analysis plugin , so I need to define a custom analyzer and a custom filter for my index.
我正在尝试使用语音分析插件 ,因此我需要为我的索引定义自定义分析器和自定义过滤器。
I tried this piece of code in order to perform the custom analysis with a soundex phonetic filter, but It fails with an exception message: 我尝试了这段代码,以便使用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}
[!!!]创建索引时出错:Elasticsearch :: Transport :: Transport :: Errors :: BadRequest [400] {“error”:“MapperParsingException [mapping [call_sentence]];嵌套:MapperParsingException [Analyzer [{tokenizer =标准,过滤= [标准,小写,变音符]}]找不到字段[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
You can also specify it in the settings call: 您也可以在设置调用中指定它:
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
Alright, I modified elasticsearch.yml config to include the phonetic analyzer 好吧,我修改了elasticsearch.yml配置以包含语音分析器
#################################### Index ####################################
index:
analysis:
analyzer:
phonetic_analyzer:
tokenizer: standard
filter: [metaphoner]
filter:
metaphoner:
type: phonetic
encoder: doublemetaphone
replace: true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.