1

I use chewy gem for elasticsearch.

I have two separate indexes: Items1Index and Items2Index. I should find Items2 by a field from the Items2Index, and filter found items by a few fields from Items1Index. (Item1 has many Items2)

I don't want repeat all fields from the Items1Index in the Items2Index.

I try implement Parent-Child Relationship.

My code is:

# 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

When I do rake chewy:reset[items2], I see the error:

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'

What happened and how can I fix the issue ?

Thanks.

chewy (0.8.4)

elasticsearch 2.4.0

Community
  • 1
  • 1
AlexMrKlim
  • 270
  • 1
  • 3
  • 15

0 Answers0