[英]ElasticSearch with Tire doesn't include custom analyzer with STI model
我有一個STI模型,希望可以用ElasticSearch和Tire搜索。 我遇到的問題是,當Tire創建映射時,它似乎忽略了第二個模型的自定義分析器。 以下是我的模型的示例。
class Account < ActiveRecord::Base
attr_accessible :name, :type
include Tire::Model::Search
include Tire::Model::Callbacks
tire.settings :analysis => {
:analyzer => {
"custom_search_analyzer" => {
"tokenizer" => "keyword",
"filter" => "lowercase"
},
"custom_index_analyzer" => {
"tokenizer" => "keyword",
"filter" => ["lowercase","substring"]
}
},
:filter => {
:substring => {
"type" => "nGram",
"min_gram" => 1,
"max_gram" => 20
}
}
} do
mapping do
indexes :id, :type => 'integer', :include_in_all => false
indexes :name, :type => 'string', :search_analyzer => :custom_search_analyzer, :index_analyzer=>:custom_index_analyzer
end
end
def to_indexed_json
hash = {}
hash[:id] = id
hash[:name] = name
hash.to_json
end
end
class StandardAccount < Account
tire.index_name 'accounts'
end
class SuperAccount < Account
tire.index_name 'accounts'
end
當我通過rake任務或通過創建模型來創建輪胎索引時,它會創建映射,但是對於繼承的模型,它不會將自定義分析器應用於它們。 如果我看一下使用
curl -XGET 'http://127.0.0.1:9200/accounts/_mapping?pretty=1'
我得到:
{
"accounts" : {
"account" : {
"properties" : {
"id" : {
"type" : "integer",
"include_in_all" : false
},
"name" : {
"type" : "string",
"index_analyzer" : "custom_index_analyzer",
"search_analyzer" : "custom_search_analyzer"
}
}
},
"standard_account" : {
"properties" : {
"id" : {
"type" : "long"
}
"name" : {
"type" : "string"
}
}
},
"super_account" : {
"properties" : {
"id" : {
"type" : "long"
}
"name" : {
"type" : "string"
}
}
}
}
}
即使我將映射聲明移到繼承的類上,它似乎也只是創建的第一個使用額外選項的模型。 我可以通過ElasticSearch手動創建索引,但是想知道是否有辦法用Tire做到這一點? 還是我設置不正確
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.