如何创建父子映射



Im 从 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

耙子弹性:导入


模型用户配置文件:以 1000 个为批次处理 37 个文档:处理...: 100% |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||时间: 0:00:01已处理 37.成功 37.跳过 0。失败 0。


模型分配:以 1000 个为批次处理 36 个文档:耙子中止!: 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'...任务:顶部 => 弹性:导入

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

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

然后再次尝试编制索引。

最新更新