I am trying to import my data using the elasticsearch-rails
and elasticsearch-model gems
.
Here's what I have in my question.rb:
belongs_to :user
...
def as_indexed_json(options={})
as_json(
user_name: user.name,
user_email: user.email
)
end
When I run the import Question.import
, I get this error:
NoMethodError: undefined method `name' for nil:NilClass
How do I import my data in a way that allows me to run some ruby against the ActiveRecord object? There are other nested associations that are 2 or 3 degrees away, and I would like to denormalize that data in Elasticsearch.
I can't use a transform
on the import because that will only work at import time. I need the code to run on create and update events too.
Aucun commentaire:
Enregistrer un commentaire