gpt4 book ai didi

ruby-on-rails - 如何创建父子映射?

转载 作者:行者123 更新时间:2023-12-02 22:45:17 24 4
gpt4 key购买 nike

我从Tire迁移到Flex
基本搜索和索引同步工作
我认为模型中的flex.parent行会自动创建_parent映射,但是会崩溃
我找不到任何父/子演示项目。

Flex.yml:

settings:
number_of_shards: 5
number_of_replicas: 1
# analysis:
# analyzer:
# tokenizer:
mappings:
userprofile:
startdatef:
type: 'date'
format: 'dateOptionalTime'
fields:
index: 'not_analyzed'
untouched:
type: 'date'
index: 'not_analyzed'
orgunit:
org_name:
type: 'string'
index: 'analyzed'
search_analyzer: orgunit_name_search
index_analyzer: orgunit_name_index
untouched:
type: 'string'
index: 'not_analyzed'

父模型:
class Userprofile < ActiveRecord::Base
include Flex::ModelIndexer
include Flex::Model
flex.sync self
has_many :assignments,
-> { order(startdate: :desc) }, dependent: :restrict_with_exception

module Search
include Flex::Scopes
flex.context = Userprofile
scope :alla, query([])
end

# rubocop:disable all
def flex_source
{
id: id,
fullname: fullname,
firstname: firstname,
lastname: lastname,
pnr: pnr,
gender: gender,
asscount: asscount,
created_at: created_at,
updated_at: updated_at,
user_id: user_id,
creator_id: creator_id,
}
end
# rubocop:enable all
end

子模型:
class Assignment < ActiveRecord::Base
include Flex::ModelIndexer
include Flex::Model
flex.parent :userprofile, 'userprofile' => 'assignment' # This makes indexing break
flex.sync self, :userprofile
belongs_to :userprofile, counter_cache: true, touch: true

module Search
include Flex::Scopes
flex.context = Assignment
scope :alla, query([])
end

def flex_source
{
# _parent_id: userprofile_id,
userprofile_id: userprofile_id,
created_at: created_at,
updated_at: updated_at
}
end
end

rake flex:import

模型用户资料:批量处理37个文档(共1000个):
正在处理...:100%|||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||||||||||||||||||||||||||||||||||| ||||||||时间:0:00:01
处理37。成功37。跳过0。失败0。

模型分配:批量处理36个文档,共1000个:
rake 中止!:0%| |预计到达时间:-:-:-
activerecord-4.0.2 / lib / active_record / relation / batches.rb:75:in find_in_batches'
400: {"error":"ElasticSearchIllegalArgumentException[Can't specify parent if no parent field has been configured]","status":400}
flex-1.0.6/lib/flex/template.rb:54:in
do_render'
...
任务:TOP => flex:import

最佳答案

在映射中,您必须指定“父”字段。只有这样,ES才能将您要索引的“_parent”字段中的ID链接到相应的索引类型。尝试将其作为模板(用适合您的索引的变量代替)。它只是将信息添加到映射中,而不删除现有信息:

curl -XPUT 'http://localhost:9200/$yourIndex/$yourChildTypeName/_mapping' -d '
{
"$yourChildTypeName" : {
"_parent" : {
"type" : "$yourParentTypeName"
}
} '

然后尝试再次索引。

关于ruby-on-rails - 如何创建父子映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20636450/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com