我从Tire迁移到Flex Basic搜索和索引同步工作我认为模型中的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
Model Userprofile:批量处理37个文件:处理......:100%|||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||||||| 时间:0:00:01已处理37.成功37.已跳过0.失败0.
模型分配:批量处理36个文件:佣金中止!:0%| | ETA: - : - : - 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" } } '
然后再次尝试索引.