searchkick索引相关的模型字段

我有一个rails应用程序,我正在从Sphinx切换到ElasticSearch并使用gem searchkick。

我有一个模型教师和模型标签(通过gem),教师可以有多个标签关联。 在Teacher模型中,我已经定义了这样的索引:

def search_data { name: name, intro: intro, bio: bio, tag_name: tags.name } end 

Name,intro和bio是教师属性,但我想索引与教师关联的标签的名称。 我怎样才能做到这一点?

它现在的方式,它索引对象的名称(关系),我如何索引标签对象内的属性名称?

在提出问题后不久,我找到了关于github页面上的一个问题的解决方案:

 def search_data { name: name, intro: intro, bio: bio, tag_name: tags.map(&:name) } end 

索引正确的属性。