searchkick index related model fields
elasticsearch, orm, ruby-on-rails, ruby-on-rails-3, searchkick
Solution
Shortly after asking the question, I found a solution on one of the issues on the github page:
def search_data
{
name: name,
intro: intro,
bio: bio,
tag_name: tags.map(&:name)
}
end
That indexes the correct attributes.
Problem
I have a rails application and I'm switching from Sphinx to ElasticSearch and using the gem searchkick. I have a model Teacher and a model Tags (via a gem), where a Teacher can have multiple tags associated. In the Teacher model I've defined the index like this: ``` def search_data { name: name, intro: intro, bio: bio, tag_name: tags.name } end ``` Name, intro and bio are Teacher attributes, but I want to index the name od the tags associeted to the teacher. How can I do this? The way it is now, it indexes the name of the object (relation), how can I index the attribute name inside the tag object?