耐嚼& ElasticSearch - 父子关系

时间:2016-11-11 08:33:39

标签: ruby-on-rails elasticsearch chewy-gem

我使用耐嚼宝石进行弹性研究。

我有两个单独的索引:Items1IndexItems2Index。我应该通过Items2中的字段找到Items2Index,并按Items1Index中的几个字段过滤找到的项目。 (Item1有很多Items2

我不想重复Items1IndexItems2Index的所有字段。

我尝试实施Parent-Child Relationship

我的代码是:

# app/chewy/items1_index.rb
class Items1Index < Chewy::Index
  define_type Item1.active, name: 'item1' do
    field :id, type: 'integer', index: :not_analyzed
    field :name, value: -> { name.strip }
  end
end


# app/chewy/items2_index.rb
class Items2Index < Chewy::Index
  define_type Item2 do
    default_import_options batch_size: 500, bulk_size: 50.megabytes, refresh: false

    root parent: 'item1', parent_id: -> { item1_id } do
      field :id, type: 'integer' # not sure, for what this block.
    end
  end
end

当我rake chewy:reset[items2]时,我看到错误:

rake aborted!
NoMethodError: undefined method `[]' for nil:NilClass
/Users/User/.rvm/gems/ruby-2.3.1@project/gems/chewy-0.8.4/lib/chewy/type/import.rb:214:in `block in fetch_indexed_objects'
/Users/User/.rvm/gems/ruby-2.3.1@project/gems/chewy-0.8.4/lib/chewy/type/import.rb:213:in `map'
/Users/User/.rvm/gems/ruby-2.3.1@project/gems/chewy-0.8.4/lib/chewy/type/import.rb:213:in `fetch_indexed_objects'
/Users/User/.rvm/gems/ruby-2.3.1@project/gems/chewy-0.8.4/lib/chewy/type/import.rb:34:in `block (2 levels) in import'
/Users/User/.rvm/gems/ruby-2.3.1@project/gems/chewy-0.8.4/lib/chewy/type/adapter/active_record.rb:32:in `import_scope'

发生了什么,我该如何解决这个问题?

感谢。

  耐嚼(0.8.4)

     

elasticsearch 2.4.0

0 个答案:

没有答案