[英]Custom Analyzer elasticsearch-rails
我在我的Rails應用程序中使用elasticsearch-rails gem來簡化與Elasticsearch的集成。 我正在嘗試使用語音分析插件 ,因此我需要為我的索引定義自定義分析器和自定義過濾器。
我嘗試了這段代碼,以便使用soundex語音過濾器執行自定義分析,但它失敗並顯示異常消息:
[!!!]創建索引時出錯: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
您也可以在設置調用中指定它:
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
好吧,我修改了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.