Ruby on rails STI的轮胎索引创建未通过analyzer,并且未提升到类型之间共享的属性
我是一名Rails开发人员。我的任务是在一个非常旧的大型Rails应用程序中从0.9升级Elasticsearch 此应用程序在其当前状态下在Elasticsearch 0.90.7上运行,并使用退役的gem轮胎。我将切换到官方支持的elasticsearch ruby(和elasticsearch模型)gems,但与此同时,我需要解决Rails模型中定义的索引定义中的突破性变化 我的问题是,我不明白Tire(或Elasticsearch-不知道这里在做什么)是如何定义类的映射的,这些类继承自具有显式定义的Ruby on rails STI的轮胎索引创建未通过analyzer,并且未提升到类型之间共享的属性,ruby-on-rails,
elasticsearch,tire,Ruby On Rails,
elasticsearch,Tire,我是一名Rails开发人员。我的任务是在一个非常旧的大型Rails应用程序中从0.9升级Elasticsearch 此应用程序在其当前状态下在Elasticsearch 0.90.7上运行,并使用退役的gem轮胎。我将切换到官方支持的elasticsearch ruby(和elasticsearch模型)gems,但与此同时,我需要解决Rails模型中定义的索引定义中的突破性变化 我的问题是,我不明白Tire(或Elasticsearch-不知道这里在做什么)是如何定义类的映射的,这些类继承自具
映射块的类
因此,守则:
有一个模特有很多孩子“标记”可以有多种类型。因此,映射如下所示:
class Tag < ActiveRecord::Base
mapping do
# some mappings that aren't causing me any problems
# and then there's these guys
indexes :name, analyzer: 'snowball', boost: 100
indexes :type
# more mappings that are happily being good, understandable mappings
end
end
然后我运行Tag.import
,以便索引数据库中的所有标记
这将更改“应用程序\开发\标记”索引映射:
$ $elasticsearch.indices.get_mapping["application_development_tags"]
=> { "tag" => {
"properties" => {
"name" => { "type" => "string", "boost" => 100.0, "analyzer" => "snowball" },
"type" => { "type" => "string" }
}
},
"atagtype" => {
"properties" => {
"name" => { "type" => "string" },
"type" => { "type" => "string" }
}
},
"btagtype" => { etc. }
}
这就是指数目前存在于生产中的方式
在升级过程中,我遇到了一个问题,即不同类型的索引具有相同的属性(“名称”),具有不同的“boost”和“analyzer”设置
问题是,我一辈子都搞不清楚在导入所有标记后,是什么代码在重新塑造索引。我认为索引:type
可能是罪魁祸首,我将类类型转换为Elasticsearch索引类型作为一个特性。但是,为什么从标记继承的每种类型的标记的名称都不以与“标记”相同的方式映射呢?理想的情况是,所有标签及其所有子项都具有相同的分析器和增强功能,因为这将保持当前行为(或尽可能接近我们将要获得的当前行为),并使其能够在较新版本的Elasticsearch中重新创建索引
我已经尝试将mapping do
块显式添加到标记模型的每个子项中,但这根本不会改变行为(不调用TagType1.create_elasticsearch\u Tag
,因此TagType1中的映射定义被忽略)。如果我从标记映射中删除analyzer和boost定义,一切都很好,但是。。。我很确定我们仍然需要analyzer和boost,最好将它们添加到所有标记类型中,而不是完全删除它们。(相关:-但提供的“答案”实际上并没有解决问题)
为了使这更复杂,我列出了所有标记类型中的所有属性,每个类型都有不同于最初定义的“标记”类型的属性
那么,有没有人能帮我弄清楚到底发生了什么,并在更新版本的Elasticsearch中成功地重新创建我的索引
编辑
我还学到了一些东西:Tag.import
更改应用程序开发标签的映射
,但$elasticsearch.search type:'application\u development\u tags',type:'Tag
不返回任何结果。只有按其他类型进行搜索才能实际返回结果
$ $elasticsearch.indices.get_mapping["application_development_tags"]
=> { "tag" => {
"properties" => {
"name" => { "type" => "string", "boost" => 100.0, "analyzer" => "snowball" },
"type" => { "type" => "string" }
}
}
}
$ $elasticsearch.indices.get_mapping["application_development_tags"]
=> { "tag" => {
"properties" => {
"name" => { "type" => "string", "boost" => 100.0, "analyzer" => "snowball" },
"type" => { "type" => "string" }
}
},
"atagtype" => {
"properties" => {
"name" => { "type" => "string" },
"type" => { "type" => "string" }
}
},
"btagtype" => { etc. }
}