1

我使用耐嚼的 gem 进行弹性搜索。

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

我不想重复Items1Index.Items2Index

我尝试实施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)

弹性搜索 2.4.0

4

0 回答 0