ElasticSearch with Tire不包括带STI模型的自定义分析器
我有一个STI模型,我希望可以使用ElasticSearch和Tire进行搜索。 我遇到的问题是当Tire创建映射时,似乎忽略了我的第二个模型的自定义分析器。 以下是我的模型示例。
class Account { :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任务还是通过创建模型,它都会创建映射,但对于inheritance的模型,它不会将自定义分析器应用于它们。 如果我看一下使用的映射
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" } } } } }
即使我将映射声明移动到inheritance的类,它似乎只是创建的第一个模型来获取额外的选项。 我可以通过ElasticSearch手动创建索引,但想知道是否有办法用Tire做到这一点? 或者我的设置不正确