Ruby on rails 带轮胎的弹性搜索';t包括带有STI型号的自定义分析仪
我有一个STI模型,我想用ElasticSearch和Tire进行搜索。我遇到的问题是,当Tire创建映射时,它似乎忽略了第二个模型的自定义分析器。下面是我的模型的一个例子Ruby on rails 带轮胎的弹性搜索';t包括带有STI型号的自定义分析仪,ruby-on-rails,
elasticsearch,tire,sti,Ruby On Rails,
elasticsearch,Tire,Sti,我有一个STI模型,我想用ElasticSearch和Tire进行搜索。我遇到的问题是,当Tire创建映射时,它似乎忽略了第二个模型的自定义分析器。下面是我的模型的一个例子 class Account < ActiveRecord::Base attr_accessible :name, :type include Tire::Model::Search include Tire::Model::Callbacks tire.settings :analysis =&g
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
我得到:
{
"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来创建索引?或者我的某些设置不正确您可能已经找到了答案,但我认为这可能会帮助您或其他有相同问题的人: -弗拉德
{
"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"
}
}
}
}
}